private async Task SaveUserRole() { try { if (roleid != -1) { var userrole = userroles.Where(item => item.UserId == userid && item.RoleId == roleid).FirstOrDefault(); if (userrole != null) { if (string.IsNullOrEmpty(effectivedate)) { userrole.EffectiveDate = null; } else { userrole.EffectiveDate = DateTime.Parse(effectivedate); } if (string.IsNullOrEmpty(expirydate)) { userrole.ExpiryDate = null; } else { userrole.ExpiryDate = DateTime.Parse(expirydate); } await UserRoleService.UpdateUserRoleAsync(userrole); } else { userrole = new UserRole(); userrole.UserId = userid; userrole.RoleId = roleid; if (string.IsNullOrEmpty(effectivedate)) { userrole.EffectiveDate = null; } else { userrole.EffectiveDate = DateTime.Parse(effectivedate); } if (string.IsNullOrEmpty(expirydate)) { userrole.ExpiryDate = null; } else { userrole.ExpiryDate = DateTime.Parse(expirydate); } await UserRoleService.AddUserRoleAsync(userrole); } await GetUserRoles(); await logger.LogInformation("User Assigned To Role {UserRole}", userrole); AddModuleMessage("User Assigned To Role", MessageType.Success); } else { AddModuleMessage("You Must Select A Role", MessageType.Warning); } } catch (Exception ex) { await logger.LogError(ex, "Error Saving User Roles {UserId} {Error}", userid, ex.Message); AddModuleMessage("Error Saving User Roles", MessageType.Error); } }