public async Task AddUserToCommitteeAsyn(CommitteeUserAssignModel committeeUserModel, string agencyCode) { Check.ArgumentNotNull(nameof(committeeUserModel), committeeUserModel); var user = await _iDMAppService.FindUserProfileByUserNameAsync(committeeUserModel.NationalIdString); List <IDMRolesModel> roles = _iDMAppService.GetIDMRoles(); IDMRolesModel iDMRolesModel = roles.FirstOrDefault(r => r.Name == committeeUserModel.RoleName); committeeUserModel.RoleName = iDMRolesModel.Name; committeeUserModel.RoleNameAr = iDMRolesModel.NormalizedName; Enums.UserRole userType = (Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), committeeUserModel.RoleName, true); if (user == null) { UserProfile userProfile = await _iDMAppService.GetUserProfileByEmployeeId(committeeUserModel.NationalIdString, agencyCode, userType); await _committeeDomainService.CheckUserExist(userProfile.Id, committeeUserModel.CommitteeId.Value); Check.ArgumentNotNull(nameof(userProfile), userProfile); await _genericCommandRepository.CreateAsync(userProfile); committeeUserModel.UserId = userProfile.Id; } else { if (!user.NotificationSetting.Any(x => x.UserRoleId == (int)userType)) { await _committeeDomainService.CheckUserExist(user.Id, committeeUserModel.CommitteeId.Value); user.AddNotificationSettings(await _notificationAppService.GetDefaultSettingByUserType(userType)); _genericCommandRepository.Update(user); } committeeUserModel.UserId = user.Id; } CommitteeUser committeeUser = new CommitteeUser(committeeUserModel.CommitteeId.Value, committeeUserModel.UserId.Value, (int)((Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), committeeUserModel.RoleName)), committeeUserModel.RelatedAgencyCode); await _genericCommandRepository.CreateAsync(committeeUser); await _genericCommandRepository.SaveAsync(); if (user == null) { if (!string.IsNullOrEmpty(committeeUser.UserProfile.Email) || !string.IsNullOrEmpty(committeeUser.UserProfile.Mobile)) { await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(committeeUser.UserProfile.Id, committeeUser.UserProfile.Email, committeeUser.UserProfile.Mobile); } } else { if (!string.IsNullOrEmpty(user.Email) || !string.IsNullOrEmpty(user.Mobile)) { await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(user.Id, user.Email, user.Mobile); } } }
public async Task AssignUsersCommittee([FromBody] CommitteeUserAssignModel committeeUserModel) { committeeUserModel.RelatedAgencyCode = User.UserRelatedAgencyCode(); await _usersService.AddUserToCommitteeAsyn(committeeUserModel, User.UserAgency()); }