From d1a4acb6f4a327f3fb50c28e2f420ade47e8e972 Mon Sep 17 00:00:00 2001 From: Wang Date: Wed, 18 Sep 2024 12:57:50 -0700 Subject: [PATCH] TH-121015: fix for user roles adding failure and ccwdata fetching error --- Server/SchoolBusAPI/Services/CCWDataService.cs | 13 +++++++++++++ Server/SchoolBusAPI/Services/UserService.cs | 15 ++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Server/SchoolBusAPI/Services/CCWDataService.cs b/Server/SchoolBusAPI/Services/CCWDataService.cs index aec55204..57c45b75 100644 --- a/Server/SchoolBusAPI/Services/CCWDataService.cs +++ b/Server/SchoolBusAPI/Services/CCWDataService.cs @@ -325,6 +325,19 @@ public CCWData GetCCW(string regi, string plate, string vin, string userId, stri } } + // TH-121015 + DateTime dateFetched = DateTime.SpecifyKind(ccwdata.DateFetched.GetValueOrDefault(), DateTimeKind.Unspecified); + DateTime icbcVipExpiry = DateTime.SpecifyKind(ccwdata.ICBCCVIPExpiry.GetValueOrDefault(), DateTimeKind.Unspecified); + DateTime nscPolicyEffectiveDate = DateTime.SpecifyKind(ccwdata.NSCPolicyEffectiveDate.GetValueOrDefault(), DateTimeKind.Unspecified); + DateTime nscPolicyExpiryDate = DateTime.SpecifyKind(ccwdata.NSCPolicyExpiryDate.GetValueOrDefault(), DateTimeKind.Unspecified); + DateTime nscPolicyStatusDate = DateTime.SpecifyKind(ccwdata.NSCPolicyStatusDate.GetValueOrDefault(), DateTimeKind.Unspecified); + ccwdata.DateFetched = dateFetched; + ccwdata.ICBCCVIPExpiry = icbcVipExpiry; + ccwdata.NSCPolicyEffectiveDate = nscPolicyEffectiveDate; + ccwdata.NSCPolicyExpiryDate = nscPolicyExpiryDate; + ccwdata.NSCPolicyStatusDate = nscPolicyStatusDate; + + if (ccwdata.Id > 0) { var bus = _context.SchoolBuss.FirstOrDefault(x => x.CCWDataId == ccwdata.Id); diff --git a/Server/SchoolBusAPI/Services/UserService.cs b/Server/SchoolBusAPI/Services/UserService.cs index 018233f8..daf3173d 100644 --- a/Server/SchoolBusAPI/Services/UserService.cs +++ b/Server/SchoolBusAPI/Services/UserService.cs @@ -325,12 +325,16 @@ public virtual IActionResult CreateUserRole(int userId, UserRoleViewModel item) user.UserRoles = new List(); } + // TH - 121015 + DateTime effectiveDate = DateTime.SpecifyKind(item.EffectiveDate, DateTimeKind.Unspecified); + DateTime expiryDate = DateTime.SpecifyKind(item.ExpiryDate.GetValueOrDefault(), DateTimeKind.Unspecified); + // create a new UserRole based on the view model. user.UserRoles.Add(new UserRole { Role = _context.Roles.First(x => x.Id == item.RoleId), - EffectiveDate = item.EffectiveDate, - ExpiryDate = item.ExpiryDate + EffectiveDate = effectiveDate, + ExpiryDate = expiryDate } ); @@ -352,9 +356,10 @@ public virtual IActionResult UpdateUserRole(int userId, int userRoleId, UserRole var userRole = _context.UserRoles .Include(x => x.Role) - .First(x => x.Id == item.Id); - - userRole.ExpiryDate = item.ExpiryDate; + .First(x => x.Id == item.Id); + // TH-121015 + DateTime expiryDate = DateTime.SpecifyKind(item.ExpiryDate.GetValueOrDefault(), DateTimeKind.Unspecified); + userRole.ExpiryDate = expiryDate; _context.SaveChanges(); return new StatusCodeResult(201);