Skip to content

Commit

Permalink
Wrap DateTimes with DateTimeKind.Utc
Browse files Browse the repository at this point in the history
  • Loading branch information
zgong-gov committed Sep 29, 2023
1 parent eba890f commit f434983
Show file tree
Hide file tree
Showing 17 changed files with 243 additions and 120 deletions.
20 changes: 13 additions & 7 deletions Server/HetsApi/Controllers/EquipmentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,25 +292,31 @@ public virtual ActionResult<EquipmentDto> EquipmentIdPut([FromRoute]int id, [Fro

// update equipment record
equipment.ConcurrencyControlNumber = item.ConcurrencyControlNumber;
equipment.ApprovedDate = item.ApprovedDate;
if (item.ApprovedDate is DateTime approvedDateUtc)
{
equipment.ApprovedDate = DateUtils.AsUTC(approvedDateUtc);
}
equipment.EquipmentCode = item.EquipmentCode;
equipment.Make = item.Make;
equipment.Model = item.Model;
equipment.Operator = item.Operator;
equipment.ReceivedDate = item.ReceivedDate;
equipment.ReceivedDate = DateUtils.AsUTC(item.ReceivedDate);
equipment.LicencePlate = item.LicencePlate;
equipment.SerialNumber = item.SerialNumber;
equipment.Size = item.Size;
equipment.YearsOfService = item.YearsOfService;
equipment.Year = item.Year;
equipment.LastVerifiedDate = item.LastVerifiedDate;
equipment.LastVerifiedDate = DateUtils.AsUTC(item.LastVerifiedDate);
equipment.IsSeniorityOverridden = item.IsSeniorityOverridden;
equipment.SeniorityOverrideReason = item.SeniorityOverrideReason;
equipment.Type = item.Type;
equipment.ServiceHoursLastYear = item.ServiceHoursLastYear;
equipment.ServiceHoursTwoYearsAgo = item.ServiceHoursTwoYearsAgo;
equipment.ServiceHoursThreeYearsAgo = item.ServiceHoursThreeYearsAgo;
equipment.SeniorityEffectiveDate = item.SeniorityEffectiveDate;
if (item.SeniorityEffectiveDate is DateTime seniorityEffectiveDateUtc)
{
equipment.SeniorityEffectiveDate = DateUtils.AsUTC(seniorityEffectiveDateUtc);
}
equipment.LicencedGvw = item.LicencedGvw;
equipment.LegalCapacity = item.LegalCapacity;
equipment.PupLegalCapacity = item.PupLegalCapacity;
Expand Down Expand Up @@ -1207,7 +1213,7 @@ public virtual ActionResult<List<DigitalFileDto>> EquipmentIdAttachmentsGet([Fro
if (attachment != null)
{
attachment.FileSize = attachment.FileContents.Length;
attachment.LastUpdateTimestamp = attachment.AppLastUpdateTimestamp;
attachment.LastUpdateTimestamp = DateUtils.AsUTC(attachment.AppLastUpdateTimestamp);
attachment.LastUpdateUserid = attachment.AppLastUpdateUserid;

// don't send the file content
Expand Down Expand Up @@ -1601,7 +1607,7 @@ private int GetLastCalledEquipmentId(
{
try
{
fiscalStart = DateUtils.AsUTC(fiscalStart);
DateTime fiscalStartUtc = DateUtils.AsUTC(fiscalStart);

// HETS-824 = BVT - Corrections to Seniority List PDF
// * This column should contain "Y" against the equipment that
Expand All @@ -1617,7 +1623,7 @@ private int GetLastCalledEquipmentId(
.FirstOrDefault(x =>
x.RentalRequest.DistrictEquipmentTypeId == districtEquipmentTypeId
&& x.RentalRequest.LocalAreaId == localAreaId
&& x.RentalRequest.AppCreateTimestamp >= fiscalStart
&& x.RentalRequest.AppCreateTimestamp >= fiscalStartUtc
&& x.Equipment.BlockNumber == currentBlock
&& x.WasAsked == true
&& x.IsForceHire != true);
Expand Down
51 changes: 38 additions & 13 deletions Server/HetsApi/Controllers/OwnerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,16 @@ public virtual ActionResult<OwnerDto> OwnersIdPut([FromRoute]int id, [FromBody]O

owner.ConcurrencyControlNumber = item.ConcurrencyControlNumber;
owner.CglCompany = item.CglCompany;
owner.CglendDate = item.CglendDate;
if (item.CglendDate is DateTime cglEndDateUtc)
{
owner.CglendDate = DateUtils.AsUTC(cglEndDateUtc);
}
owner.CglPolicyNumber = item.CglPolicyNumber;
owner.LocalAreaId = item.LocalArea.LocalAreaId;
owner.WorkSafeBcexpiryDate = item.WorkSafeBcexpiryDate;
if (item.WorkSafeBcexpiryDate is DateTime workSafeBcExpiryDateUtc)
{
owner.WorkSafeBcexpiryDate = DateUtils.AsUTC(workSafeBcExpiryDateUtc);
}
owner.WorkSafeBcpolicyNumber = item.WorkSafeBcpolicyNumber;
owner.IsMaintenanceContractor = item.IsMaintenanceContractor;
owner.OrganizationName = item.OrganizationName;
Expand Down Expand Up @@ -468,21 +474,23 @@ public virtual ActionResult<OwnerDto> OwnersIdStatusPut([FromRoute]int id, [From
public virtual ActionResult<OwnerDto> OwnersPost([FromBody]OwnerDto item)
{
// not found
if (item == null) return new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)));
if (item == null)
return new NotFoundObjectResult(
new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)));

// get status id
int? statusId = StatusHelper.GetStatusId(item.Status, "ownerStatus", _context);
if (statusId == null) return new BadRequestObjectResult(new HetsResponse("HETS-23", ErrorViewModel.GetDescription("HETS-23", _configuration)));
if (statusId == null)
return new BadRequestObjectResult(
new HetsResponse("HETS-23", ErrorViewModel.GetDescription("HETS-23", _configuration)));

// create record
HetOwner owner = new HetOwner
HetOwner owner = new()
{
OwnerStatusTypeId = (int)statusId,
CglCompany = item.CglCompany,
CglendDate = item.CglendDate,
CglPolicyNumber = item.CglPolicyNumber,
LocalAreaId = item.LocalArea.LocalAreaId,
WorkSafeBcexpiryDate = item.WorkSafeBcexpiryDate,
WorkSafeBcpolicyNumber = item.WorkSafeBcpolicyNumber,
IsMaintenanceContractor = item.IsMaintenanceContractor ?? false,
OrganizationName = item.OrganizationName,
Expand All @@ -499,6 +507,16 @@ public virtual ActionResult<OwnerDto> OwnersPost([FromBody]OwnerDto item)
MeetsResidency = item.MeetsResidency
};

if (item.CglendDate is DateTime cglEndDateUtc)
{
owner.CglendDate = DateUtils.AsUTC(cglEndDateUtc);
}

if (item.WorkSafeBcexpiryDate is DateTime workSafeBcExpiryDateUtc)
{
owner.WorkSafeBcexpiryDate = DateUtils.AsUTC(workSafeBcExpiryDateUtc);
}

if (!string.IsNullOrEmpty(item.RegisteredCompanyNumber))
{
owner.RegisteredCompanyNumber = item.RegisteredCompanyNumber;
Expand Down Expand Up @@ -1172,15 +1190,14 @@ public virtual ActionResult<List<EquipmentDto>> OwnersIdEquipmentTransferPost(
Make = equipmentToTransfer.Make,
Model = equipmentToTransfer.Model,
Operator = equipmentToTransfer.Operator,
ReceivedDate = equipmentToTransfer.ReceivedDate,
LicencePlate = equipmentToTransfer.LicencePlate,
SerialNumber = equipmentToTransfer.SerialNumber,
Size = equipmentToTransfer.Size,
PayRate = equipmentToTransfer.PayRate,
RefuseRate = equipmentToTransfer.RefuseRate,
YearsOfService = 0,
Year = equipmentToTransfer.Year,
LastVerifiedDate = equipmentToTransfer.LastVerifiedDate,
LastVerifiedDate = DateUtils.AsUTC(equipmentToTransfer.LastVerifiedDate),
IsSeniorityOverridden = false,
SeniorityOverrideReason = "",
Type = equipmentToTransfer.Type,
Expand All @@ -1193,6 +1210,11 @@ public virtual ActionResult<List<EquipmentDto>> OwnersIdEquipmentTransferPost(
PupLegalCapacity = equipmentToTransfer.PupLegalCapacity
};

if (equipmentToTransfer.ReceivedDate is DateTime receivedDateUtc)
{
newEquipment.ReceivedDate = DateUtils.AsUTC(receivedDateUtc);
}

newEquipment.HetEquipmentAttachments =
GetEquipmentAttachments(newEquipment.HetEquipmentAttachments, equipmentToTransfer);

Expand Down Expand Up @@ -1311,7 +1333,10 @@ private static HetEquipment IncludeSeniorityWithEquipment(
newEquipment.ServiceHoursThreeYearsAgo = equipmentToTransfer.ServiceHoursThreeYearsAgo;
newEquipment.YearsOfService = equipmentToTransfer.YearsOfService;
newEquipment.Seniority = equipmentToTransfer.Seniority;
newEquipment.ApprovedDate = equipmentToTransfer.ApprovedDate;
if (equipmentToTransfer.ApprovedDate is DateTime approvedDateUtc)
{
newEquipment.ApprovedDate = DateUtils.AsUTC(approvedDateUtc);
}
}
return newEquipment;
}
Expand All @@ -1323,11 +1348,11 @@ private void UpdateRentalAgreements(

// we also need to update all of the associated rental agreements
// (for this fiscal year)
fiscalStart = DateUtils.AsUTC(fiscalStart);
DateTime fiscalStartUtc = DateUtils.AsUTC(fiscalStart);

IQueryable<HetRentalAgreement> agreements = _context.HetRentalAgreements
.Where(x => x.EquipmentId == equipmentToTransfer.EquipmentId &&
x.DatedOn >= fiscalStart);
x.DatedOn >= fiscalStartUtc);

foreach (HetRentalAgreement agreement in agreements)
{
Expand Down Expand Up @@ -1366,7 +1391,7 @@ public virtual ActionResult<List<DigitalFileDto>> OwnersIdAttachmentsGet([FromRo
if (attachment != null)
{
attachment.FileSize = attachment.FileContents.Length;
attachment.LastUpdateTimestamp = attachment.AppLastUpdateTimestamp;
attachment.LastUpdateTimestamp = DateUtils.AsUTC(attachment.AppLastUpdateTimestamp);
attachment.LastUpdateUserid = attachment.AppLastUpdateUserid;
attachment.UserName = UserHelper.GetUserName(attachment.LastUpdateUserid, _context);
attachments.Add(attachment);
Expand Down
6 changes: 3 additions & 3 deletions Server/HetsApi/Controllers/ProjectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ public virtual ActionResult<List<TimeRecordDto>> ProjectsIdTimeRecordsPost([From
time.Hours = item.Hours;
time.TimePeriod = item.TimePeriod;
time.TimePeriodTypeId = (int)timePeriodTypeId;
time.WorkedDate = item.WorkedDate;
time.WorkedDate = DateUtils.AsUTC(item.WorkedDate);
}
else // add time record
{
Expand All @@ -669,7 +669,7 @@ public virtual ActionResult<List<TimeRecordDto>> ProjectsIdTimeRecordsPost([From
Hours = item.Hours,
TimePeriod = item.TimePeriod,
TimePeriodTypeId = (int)timePeriodTypeId,
WorkedDate = item.WorkedDate
WorkedDate = DateUtils.AsUTC(item.WorkedDate)
};

_context.HetTimeRecords.Add(time);
Expand Down Expand Up @@ -759,7 +759,7 @@ public virtual ActionResult<List<DigitalFileDto>> ProjectsIdAttachmentsGet([From
if (attachment != null)
{
attachment.FileSize = attachment.FileContents.Length;
attachment.LastUpdateTimestamp = attachment.AppLastUpdateTimestamp;
attachment.LastUpdateTimestamp = DateUtils.AsUTC(attachment.AppLastUpdateTimestamp);
attachment.LastUpdateUserid = attachment.AppLastUpdateUserid;
attachment.UserName = UserHelper.GetUserName(attachment.LastUpdateUserid, _context);
attachments.Add(attachment);
Expand Down
Loading

0 comments on commit f434983

Please sign in to comment.