public async Task <ActionResult> AssignCommitteesToBranch(BranchCommitteeModel branchUserModel) { if (!ModelState.IsValid) { AddError(Resources.TenderResources.ErrorMessages.ModelDataError); return(RedirectToAction(nameof(AssignCommitteesToBranch), new { branchIdString = Util.Encrypt(branchUserModel.BranchId) })); } try { ClearCommitteesCache(); await _ApiClient.PostAsync("Branch/AssignCommitteesBranch", null, branchUserModel); AddMessage(Resources.SharedResources.Messages.DataSaved); return(RedirectToAction(nameof(AssignCommitteesToBranch), new { branchIdString = Util.Encrypt(branchUserModel.BranchId) })); } 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 <ActionResult> AssignCommitteesToBranch(string branchIdString) { BranchCommitteeModel branchUserModel = new BranchCommitteeModel(); try { branchUserModel.BranchId = Util.Decrypt(branchIdString); BranchModel branch = await _ApiClient.GetAsync <BranchModel>("Branch/GetById/" + branchUserModel.BranchId.ToString(), null); branchUserModel.BranchName = branch.BranchName; branchUserModel.Committees = await _ApiClient.GetListAsync <CommitteeModel>("Branch/GetCommitteesNotAssignedToBranch/" + branchUserModel.BranchId, null); return(View(branchUserModel)); } catch (AuthorizationException ex) { throw ex; } catch (BusinessRuleException ex) { return(JsonErrorMessage(ex.Message)); } catch (Exception ex) { _logger.LogError(ex.ToString(), ex); return(JsonErrorMessage(Resources.TenderResources.ErrorMessages.UnexpectedError)); } }
public async Task ShoulAddCommitteeThrowException() { BranchCommitteeModel branchCommitteeModel = new BranchCommitteeModel(); branchCommitteeModel.CommitteeIdsString = ""; await Assert.ThrowsAsync <BusinessRuleException>(async() => await _sutBranchAppService.AddCommittee(branchCommitteeModel)); }
public async Task <BranchCommitteeModel> Put(BranchCommitteeModel branchCommitteeModel) { var branchCommitteeObject = _mapper.Map <BranchCommittee>(branchCommitteeModel); var branchCommitteeResult = await _branchCommitteeService.UpdateAsync(branchCommitteeObject); branchCommitteeModel = _mapper.Map <BranchCommitteeModel>(branchCommitteeResult); return(branchCommitteeModel); }
public async Task AddCommittee(BranchCommitteeModel branchCommitteeModel) { Check.ArgumentNotNull(nameof(branchCommitteeModel), branchCommitteeModel); if (string.IsNullOrEmpty(branchCommitteeModel.CommitteeIdsString)) { throw new BusinessRuleException(Resources.SharedResources.ErrorMessages.ModelDataError); } branchCommitteeModel.CommitteeIds = (branchCommitteeModel.CommitteeIdsString.Split(',').Where(w => !string.IsNullOrEmpty(w)).Select(d => int.Parse(d)).ToList()); foreach (var committee in branchCommitteeModel.CommitteeIds) { await _branchServiceDomain.CheckCommitteeExist(committee, branchCommitteeModel.BranchId); var branchUser = new BranchCommittee(branchCommitteeModel.BranchId, committee); await _genericCommandRepository.CreateAsync(branchUser); } await _genericCommandRepository.SaveAsync(); }
public async Task AssignCommitteesBranch([FromBody] BranchCommitteeModel branchCommitteeModel) { await _branchService.AddCommittee(branchCommitteeModel); }