public async Task AddUserToBranchAsyn(BranchUserAssignModel branchUserModel, string agencyCode) { Check.ArgumentNotNull(nameof(branchUserModel), branchUserModel); var user = await _iDMAppService.FindUserProfileByUserNameAsync(branchUserModel.NationalIdString); Enums.UserRole userRole = ((Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), branchUserModel.RoleName)); if (user == null) { ManageUsersAssignationModel emp = await _iDMAppService.GetMonafastatEmployeeDetailById(agencyCode, branchUserModel.NationalIdString, ""); UserProfile userProfile = new UserProfile(emp.userId, emp.nationalId, emp.fullName, emp.mobileNumber, emp.email, await _notificationAppService.GetDefaultSettingByUserType(userRole)); Check.ArgumentNotNull(nameof(userProfile), userProfile); await _genericCommandRepository.CreateAsync(userProfile); branchUserModel.UserId = userProfile.Id; } else { if (!user.NotificationSetting.Any(x => x.UserRoleId == (int)userRole)) { await _branchServiceDomain.CheckUserExist(user.Id, branchUserModel.BranchId, branchUserModel.RoleName); user.AddNotificationSettings(await _notificationAppService.GetDefaultSettingByUserType(userRole)); _genericCommandRepository.Update(user); } branchUserModel.UserId = user.Id; } var branchUser = new BranchUser(branchUserModel.BranchId, branchUserModel.UserId.Value, (int)userRole, branchUserModel.RelatedAgencyCode, branchUserModel.EstimatedValueFrom, branchUserModel.EstimatedValueTo); await _genericCommandRepository.CreateAsync(branchUser); await _genericCommandRepository.SaveAsync(); if (user == null) { if (!string.IsNullOrEmpty(branchUser.UserProfile.Email) || !string.IsNullOrEmpty(branchUser.UserProfile.Mobile)) { await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(branchUser.UserProfile.Id, branchUser.UserProfile.Email, branchUser.UserProfile.Mobile); } } else { if (!string.IsNullOrEmpty(user.Email) || !string.IsNullOrEmpty(user.Mobile)) { await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(user.Id, user.Email, user.Mobile); } } }
public async Task AddUserAsyn(BranchUserModel branchUserModel, string agencyCode) { Check.ArgumentNotNull(nameof(branchUserModel), branchUserModel); var user = await _iDMAppService.FindUserProfileByUserNameAsync(branchUserModel.UserName); if (user != null) { _branchServiceDomain.AssignBranchUserExist(branchUserModel.BranchId, branchUserModel.RoleName, user); } List <IDMRolesModel> roles = _iDMAppService.GetIDMRoles(); IDMRolesModel iDMRolesModel = roles.FirstOrDefault(r => r.Name == branchUserModel.RoleName); branchUserModel.RoleName = iDMRolesModel.Name; branchUserModel.RoleArName = iDMRolesModel.NormalizedName; Enums.UserRole userType = (Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), branchUserModel.RoleName, true); UserProfile userProfile = new UserProfile(); if (user == null) { userProfile = await _iDMAppService.GetUserProfileByEmployeeId(branchUserModel.UserName, agencyCode, userType); Check.ArgumentNotNull(nameof(userProfile), userProfile); await _genericCommandRepository.CreateAsync(userProfile); branchUserModel.UserId = userProfile.Id; } else { var defaultSettingsForUserType = await _notificationAppService.GetDefaultSettingByUserType(userType); if (user.NotificationSetting.Count(x => x.UserRoleId == (int)userType) < defaultSettingsForUserType.Count) { await _branchServiceDomain.CheckUserExist(user.Id, branchUserModel.BranchId, branchUserModel.RoleName); user.AddNotificationSettings(defaultSettingsForUserType); _genericCommandRepository.Update(user); } branchUserModel.UserId = user.Id; } var branchUser = new BranchUser(branchUserModel.BranchId, branchUserModel.UserId, (int)((Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), branchUserModel.RoleName)), branchUserModel.RelatedAgencyCode, branchUserModel.EstimatedValueFrom, branchUserModel.EstimatedValueTo); await _genericCommandRepository.CreateAsync(branchUser); await _genericCommandRepository.SaveAsync(); if (user != null) { if (!string.IsNullOrEmpty(user.Email) || !string.IsNullOrEmpty(user.Mobile)) { await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(user.Id, user.Email, user.Mobile); } } else { if (!string.IsNullOrEmpty(userProfile.Email) || !string.IsNullOrEmpty(userProfile.Mobile)) { await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(userProfile.Id, userProfile.Email, userProfile.Mobile); } } }
public async Task AddUserAsyn(CommitteeUserModel committeeUserModel, string agencyCode) { Check.ArgumentNotNull(nameof(committeeUserModel), committeeUserModel); var user = await _iDMAppService.FindUserProfileByUserNameAsync(committeeUserModel.UserName); List <IDMRolesModel> roles = _iDMAppService.GetIDMRoles(); IDMRolesModel iDMRolesModel = roles.FirstOrDefault(r => r.Name == committeeUserModel.RoleName); Enums.UserRole userType = (Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), iDMRolesModel.Name, true); UserProfile userProfile = new UserProfile(); if (user == null) { userProfile = await _iDMAppService.GetUserProfileByEmployeeId(committeeUserModel.UserName, agencyCode, userType); Check.ArgumentNotNull(nameof(userProfile), userProfile); await _committeeDomainService.CheckUserExist(userProfile.Id, committeeUserModel.CommitteeId); await _genericCommandRepository.CreateAsync(userProfile); committeeUserModel.UserId = userProfile.Id; } else { var defaultSettingsForUserType = await _notificationAppService.GetDefaultSettingByUserType(userType); if (user.NotificationSetting.Count(x => x.UserRoleId == (int)userType) < defaultSettingsForUserType.Count) { await _committeeDomainService.CheckUserExist(user.Id, committeeUserModel.CommitteeId); user.AddNotificationSettings(defaultSettingsForUserType); _genericCommandRepository.Update(user); } committeeUserModel.UserId = user.Id; } CommitteeUser committeeUser = new CommitteeUser(committeeUserModel.CommitteeId, committeeUserModel.UserId, (int)((Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), iDMRolesModel.Name)), committeeUserModel.RelatedAgencyCode); await _genericCommandRepository.CreateAsync(committeeUser); await _genericCommandRepository.SaveAsync(); if (user != null) { if (!string.IsNullOrEmpty(user.Email) || !string.IsNullOrEmpty(user.Mobile)) { await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(user.Id, user.Email, user.Mobile); } } else { if (!string.IsNullOrEmpty(userProfile.Email) || !string.IsNullOrEmpty(userProfile.Mobile)) { await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(userProfile.Id, userProfile.Email, userProfile.Mobile); } } }