Beispiel #1
0
        public IActionResult OnPostEdit(EditInventoryVM command)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToPage("Index"));
            }

            var result = _inventoryApplication.Edit(command);

            return(new JsonResult(result));
        }
        public OperationResult Edit(EditInventoryVM command)
        {
            OperationResult result = new OperationResult();

            if (_inventoryRepository.IsExist(i => i.ProductId == command.ProductId && i.Price == command.Price && i.Id != command.Id))
            {
                return(result.Failed(ValidateMessage.IsDuplicated));
            }

            var inventory = _inventoryRepository.Get(command.Id);

            if (inventory == null)
            {
                return(result.Failed(ValidateMessage.IsExist));
            }

            inventory.Edit(command.ProductId, command.Price);
            _inventoryRepository.SaveChanges();

            return(result.Succeeded());
        }