public async Task <ActionResult> AssignUsersToBranch(BranchUserModel branchUserModel) { if (!ModelState.IsValid) { AddError(Resources.TenderResources.ErrorMessages.ModelDataError); return(RedirectToAction(nameof(AssignUsersToBranch), new { branchIdString = Util.Encrypt(branchUserModel.BranchId) })); } try { ClearCommitteesCache(); await _ApiClient.PostAsync("Branch/AssignUsersBranch", null, branchUserModel); AddMessage(Resources.SharedResources.Messages.DataSaved); return(RedirectToAction(nameof(AssignUsersToBranch), new { branchIdString = Util.Encrypt(branchUserModel.BranchId) })); } catch (AuthorizationException ex) { throw ex; } catch (BusinessRuleException ex) { AddError(ex.Message); return(RedirectToAction(nameof(AssignUsersToBranch), new { branchIdString = Util.Encrypt(branchUserModel.BranchId) })); } catch (Exception ex) { _logger.LogError(ex.ToString(), ex); AddError(Resources.TenderResources.ErrorMessages.UnexpectedError); return(RedirectToAction(nameof(Index))); } }
public async Task <ActionResult> AssignUsersToBranch(string branchIdString) { try { BranchUserSearchCriteriaModel criteria = new BranchUserSearchCriteriaModel() { BranchId = Util.Decrypt(branchIdString) }; BranchUserModel branchUserModel = await _ApiClient.PostAsync <BranchUserModel>("Branch/GetBranchUserModel/", null, criteria); return(View(branchUserModel)); } catch (AuthorizationException ex) { throw ex; } catch (BusinessRuleException ex) { AddError(ex.Message); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { _logger.LogError(ex.ToString(), ex); AddError(Resources.TenderResources.ErrorMessages.UnexpectedError); return(RedirectToAction(nameof(Index))); } }
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 <BranchUserModel> GetBranchUserModel([FromBody] BranchUserSearchCriteriaModel criteria) { BranchUserModel branchUserModel = new BranchUserModel(); BranchModel branchObject = await _branchService.FindById(criteria.BranchId); branchUserModel.BranchId = branchObject.BranchId; branchUserModel.BranchName = branchObject.BranchName; branchUserModel.Users = await GetIDMUsersSearch(criteria); return(branchUserModel); }
public async Task AssignUsersBranchTest() { _claims = new Claim[1] { new Claim(IdentityConfigs.Claims.SelectedGovAgency, "022001000000,022001000000") }; _branchController = _branchController.WithIdentity(_claims); var requestModel = new BranchUserModel() { BranchId = 2644, UserName = "******", RoleName = RoleNames.MonafasatAdmin }; await _branchController.AssignUsersBranch(requestModel); }
public async Task AssignUsersBranch([FromBody] BranchUserModel branchUserModel) { branchUserModel.RelatedAgencyCode = User.UserRelatedAgencyCode(); await _branchService.AddUserAsyn(branchUserModel, User.UserAgency()); }