The challenge I have is I need to keep a time property, set to a user selectable timezone, that was a property of an entity.
For example, the user is in CST/CDT. The Tenant HQ is in EST. The entity is in PST.
They want to set a time for when that entity's deadline. 8:00AM PST, for example.
If using Tenant, the date time would be off by time difference between PST and EST. If the user is in CST, that time would be represented.
ANZ helpfully converts 8:00AM, if entered into a datetime field, to UTC, and stores that to the database. This is normally good. Except, when my user selects PST for the entity, then chooses 8:00AM for the deadline, ANZ uses settings to convert that datetime to the time zone for the tenant and or the user.
I need the time to be based on the time zone the user selected for the entity.
I am trying to solve this by using the entity's selected time zone, and setting the selected time to that selected time zone for the entity, then converting that to UTC.
TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(input.TimeZone);
DateTime _dtTZ = DateTime.SpecifyKind(input.DeadlineTZ, DateTimeKind.Unspecified); // Strip the UTC from the time supplied
DateTime _dt = TimeZoneInfo.ConvertTime(_dtTZ, timeZoneInfo, TimeZoneInfo.Utc); // Convert it as unspecified to a UTC
input.Deadline = _dt;
In this scenario, if the user picks 8:00AM PST, what's posted to the server is 8:00 AM UTC. I set it's kind to be unspecified, then convert the new DateTime using the TimeZoneInfo the user selected. When this gets converted from 8:00 AM PST, I get 3PM UTC.
Basically, I may have a tenant in one time zone, with a user in another, setting a time for entity based on the ENTITY'S timezone.
I have an enitity where the user specifies a time of day to notify employees in a work shift.
They set the time, for example, 7:30 AM.
The DateTime kind of the field I get on save is UTC. So I think I'm doing this correctly.
I used the TimeZone dropdown to let them pick the time zone for shift.
When the view model comes down, the time is in UTC.
Would I do better to modify the view objects and put the time for the selected time zone on that, use that in the views, then, on save, convert that with moment to the UTC property when posting back?
Or -
Would I do better to modify the view model and convert it to the time zone for the entity, and then convert it back when I save?
Am I doing this correctly in all my projects' startup.cs?
app.UseAbp(options =>
{
Clock.Provider = ClockProviders.Utc;
options.UseAbpRequestLocalization = false; //used below: UseAbpRequestLocalization
});
Yes.
It calls ClearForm, which sets the entity back to the model. If the user hits save again it creates two entities.
I'm going to mark this resolved. I've got a fairly good deployment going. I'm using GoCD + a powershell build script and it's doing a great job.
Understood - What I was asking is if I have an entity where I need to note what time zone it exists in, how do I set it as a property.
I'm currently using a string, and the name of the time zone.
That seems to be how ABP does it.
Resolved - the DoWork method must be a [UnitOfWork]
As per https://aspnetboilerplate.com/Pages/Documents/Background-Jobs-And-Workers
Do we do it in both MVC and Host?
They are registered in both - or is it if we're only running the API do it there, and if we're doing it in MVC do it there?
Thanks
I think this is working, but not without my setting the TenantID to null and clearing the MayHaveTenant filter.
I'll keep working with it - but I have something working at the moment. Probably needs refinement.
I created my DomainService in Core project, right next to the entity.
I exposed GetAsync, injecting the repo and inheriting from workDomainServiceBase
I injected the domain service into the Controller, and updated the service in Application to inject the Domain service as well.
Then, in the GetAsync function in the service in application, I called the getAsync in the domain service.
In the public controller, I had to create a unit of work method that called the getAync in the domain service, but it would fair if I didn't set TenantID to null and clear the MayHaveTenant filter.
Based on this: https://support.aspnetzero.com/QA/Questions/9108/Update-an-Entity-from-the-public-website#answer-8ace2a6c-a66e-3758-43c5-39f57cb830ef
Do I need to, in effect, take any methods I'd call in the normal application service, and move them to this DomainService?
using only get:
In an app service, for example, I'd take the method: GetEmployeeForView
And instead of calling employeeRepository.GetAsync(id); to get an employee entity, i'd instead call employeeDomainService.GetAysnc(id); and return it to the app service from the domain service (referencing the domain service).
THen, in my controller, I'd reference the domain service, and get my entity directly.
Correct?