Esempio n. 1
0
        public async Task ShouldAddSuccess()
        {
            List <InputMandatoryListProductViewModel> inputMandatoryListProductViewModels = new List <InputMandatoryListProductViewModel>();
            InputMandatoryListProductViewModel        product = new InputMandatoryListProductViewModel()
            {
                CSICode       = "1010",
                NameAr        = "First Product",
                NameEn        = "First Product",
                PriceCelling  = 10,
                DescriptionAr = "Hello First Product",
                DescriptionEn = "English Description",
            };

            inputMandatoryListProductViewModels.Add(product);
            InputMandatoryListViewModel mandatoryList = new InputMandatoryListViewModel()
            {
                DivisionCode   = "1010",
                DivisionNameAr = "Name Ar",
                DivisionNameEn = "Name En",
                StatusId       = 1,
                Products       = inputMandatoryListProductViewModels
            };

            _mapper.Setup(x => x.Map <Core.Entities.MandatoryList>(It.IsAny <InputMandatoryListViewModel>())).Returns(() =>
            {
                return(new MandatoryListDefault().GetMandatoryListWithProdcuts());
            });
            await _sut.Add(mandatoryList);

            _mandatoryListCommands.Verify(m => m.Add(It.IsAny <Core.Entities.MandatoryList>()), Times.Once);
        }
        public async Task <MandatoryListViewModel> Add(InputMandatoryListViewModel mandatoryList)
        {
            var entity = _mapper.Map <MandatoryList>(mandatoryList);

            entity.Add();
            await _mandatoryListCommands.Add(entity);

            return(_mapper.Map <MandatoryListViewModel>(entity));
        }
        public async Task Update(InputMandatoryListViewModel mandatoryList)
        {
            var entity   = _mapper.Map <MandatoryList>(mandatoryList);
            var dbEntity = await _mandatoryListQueries.Find(entity.Id);

            if (dbEntity.StatusId == (int)Enums.MandatoryListStatus.Approved)
            {
                await AddChangeRequest(entity, dbEntity);
            }
            else
            {
                dbEntity.Update(entity);
                await _mandatoryListCommands.Update(dbEntity);
            }
        }
Esempio n. 4
0
        public async Task ShouldAddThrowException()
        {
            InputMandatoryListViewModel mandatoryList = new InputMandatoryListViewModel()
            {
                DivisionCode   = "1010",
                DivisionNameAr = "Name Ar",
                DivisionNameEn = "Name En",
                StatusId       = 1,
            };

            _mapper.Setup(x => x.Map <Core.Entities.MandatoryList>(It.IsAny <InputMandatoryListViewModel>())).Returns(() =>
            {
                return(new MandatoryListDefault().GetMandatoryListWithOutProdcuts());
            });
            await Assert.ThrowsAsync <BusinessRuleException>(async() => await _sut.Add(mandatoryList));
        }
        public async Task <IActionResult> Edit(InputMandatoryListViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                AddError(FormatErrorMessage(GetModalStateErrors()));
                return(View(viewModel));
            }

            try
            {
                await _apiClient.PostAsync("MandatoryList/Update", null, viewModel);

                if (viewModel.SendToApproval)
                {
                    await _apiClient.PostAsync("MandatoryList/SendToApproval/" + viewModel.Id, null, null);
                }

                AddMessage(Resources.SharedResources.Messages.DataSaved);
                return(RedirectToAction(nameof(Index)));
            }
            catch (BusinessRuleException ex)
            {
                AddError(ex.Message);
                return(View(viewModel));
            }
            catch (AuthorizationException ex)
            {
                AddError(ex.Message);
                return(RedirectToAction(nameof(Index)));
            }
            catch (UnHandledAccessException ex)
            {
                AddError(ex.Message);
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                AddError(ex.Message);
                return(View(viewModel));
            }
        }
Esempio n. 6
0
        public async Task ShouldFindForEditSuccess()
        {
            List <InputMandatoryListProductViewModel> inputMandatoryListProductViewModels = new List <InputMandatoryListProductViewModel>();
            InputMandatoryListProductViewModel        product = new InputMandatoryListProductViewModel()
            {
                CSICode       = "1010",
                NameAr        = "First Product",
                NameEn        = "First Product",
                PriceCelling  = 10,
                DescriptionAr = "Hello First Product",
                DescriptionEn = "English Description",
            };

            inputMandatoryListProductViewModels.Add(product);
            InputMandatoryListViewModel mandatoryList = new InputMandatoryListViewModel()
            {
                DivisionCode   = "1010",
                DivisionNameAr = "Name Ar",
                DivisionNameEn = "Name En",
                StatusId       = 1,
                Products       = inputMandatoryListProductViewModels
            };


            mandatoryListQueries.Setup(m => m.ProjectedFind(It.IsAny <int>()))
            .Returns(() =>
            {
                return(Task.FromResult <MandatoryListViewModel>(new MandatoryListDefault().GetMandatoryListViewModelData()));
            });
            _mapper.Setup(x => x.Map <InputMandatoryListViewModel>(It.IsAny <MandatoryListViewModel>())).Returns(() =>
            {
                return(mandatoryList);
            });

            var result = await _sut.FindForEdit(1);

            Assert.NotNull(result);
        }
 public async Task Update([FromBody] InputMandatoryListViewModel viewModel)
 {
     await _mandatoryListAppService.Update(viewModel);
 }
 public async Task <MandatoryListViewModel> Add([FromBody] InputMandatoryListViewModel viewModel)
 {
     return(await _mandatoryListAppService.Add(viewModel));
 }