Exemplo n.º 1
0
        public async Task <IActionResult> Save(ProduceViewModel model)
        {
            if (ModelState.IsValid)
            {
                ProduceDTO response = await _greenApiService.Save(new ProduceDTO()
                {
                    Id    = model.Id,
                    Name  = model.Name,
                    Price = model.Price.GetValueOrDefault(0),
                    Stock = model.Stock.GetValueOrDefault(0),
                });

                model.Id = response.Id;

                if (model.Id == 0)
                {
                    AddNotification("danger", "Save Failed!");
                }
                else
                {
                    AddNotification("success", "Save Succeeded!");
                }
            }

            return(View("ManageProduce", model));
        }
Exemplo n.º 2
0
        public ProduceViewModel Rebuild(ProduceEditModel model)
        {
            var produceViewModel = new ProduceViewModel
            {
                ProduceID            = model.ProduceID,
                ProduceCode          = model.ProduceCode,
                ProduceName          = model.ProduceName,
                IsActive             = model.IsActive,
                SelectedMasterGroup  = model.SelectedMasterGroup,
                SelectedProduceGroup = model.SelectedProduceGroup
            };

            produceViewModel.MasterGroupList =
                _masterGroupService.Query()
                .Select(m => new dropdownlistModel {
                Id = m.MasterGroupID, Name = m.MasterGroupName
            })
                .ToList();
            produceViewModel.ProduceGroupList =
                _produceGroupService.Query()
                .Select(m => new dropdownlistModel {
                Id = m.ProduceGroupID, Name = m.ProduceGroupName
            })
                .ToList();
            //produceViewModel.TransactionTaxCodeList =
            //    _transactionTaxCodeService.Query()
            //        .Select(m => new dropdownlistModel {Id = m.TransactionTaxCodeID, Name = m.TransactionTaxCodeValue})
            //        .ToList();
            return(produceViewModel);
        }
Exemplo n.º 3
0
        public void ValidationTest(string name, decimal?price, int?stock, bool expectedResult, int expectedValidationResults)
        {
            ProduceViewModel model = new ProduceViewModel()
            {
                Name  = name,
                Price = price,
                Stock = stock,
            };

            ValidationContext       context = new ValidationContext(model);
            List <ValidationResult> results = new List <ValidationResult>();
            bool isModelStateValid          = Validator.TryValidateObject(model, context, results, true);

            Assert.Equal(expectedResult, isModelStateValid);
            Assert.Equal(expectedValidationResults, results.Count);
        }