Exemplo n.º 1
0
        public IActionResult Create(CreateInventoryVM inventoryVM)
        {
            Inventory inventory = inventoryVM.Inventory;
            int       storeId   = inventory.Store1Id;
            int       itemId    = inventory.Item1Id;


            var existingInventory = _inventoryRepository.GetInventoryByStoreItemIds(storeId, itemId);

            if (ModelState.IsValid && existingInventory == null)
            {
                _inventoryRepository.CreateAddInventory(inventory);
                return(RedirectToAction("Index"));
            }
            inventoryVM.StoreSelectList = _inventoryRepository.GetAllStores().Select(i => new SelectListItem
            {
                Text  = i.StoreAddress,
                Value = i.StoreId.ToString()
            });
            inventoryVM.ItemSelectList = _inventoryRepository.GetAllItems().Select(i => new SelectListItem
            {
                Text  = i.ItemName,
                Value = i.ItemId.ToString()
            });

            return(View(inventoryVM));
        }
Exemplo n.º 2
0
        public IActionResult Create(int?id)
        {
            CreateInventoryVM inventoryVM = new CreateInventoryVM()
            {
                Inventory       = new Inventory(),
                StoreSelectList = _inventoryRepository.GetAllStores().Select(i => new SelectListItem
                {
                    Text  = i.StoreAddress,
                    Value = i.StoreId.ToString()
                }),
                ItemSelectList = _inventoryRepository.GetAllItems().Select(i => new SelectListItem
                {
                    Text  = i.ItemName,
                    Value = i.ItemId.ToString()
                }),
            };

            if (id == null || id == 0)
            {
                return(View(inventoryVM));
            }
            else
            {
                inventoryVM.Inventory = _inventoryRepository.GetInventoryById((int)id);
                if (inventoryVM.Inventory == null)
                {
                    return(NotFound());
                }
            }
            return(View(inventoryVM));
        }
Exemplo n.º 3
0
        public IActionResult OnPostCreate(CreateInventoryVM command)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToPage("Index"));
            }

            var result = _inventoryApplication.Create(command);

            return(new JsonResult(result));
        }
        public OperationResult Create(CreateInventoryVM command)
        {
            OperationResult result = new OperationResult();

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

            var inventory = new Inventory(command.ProductId, command.Price);

            _inventoryRepository.Create(inventory);
            _inventoryRepository.SaveChanges();

            return(result.Succeeded());
        }