public ActionResult AddInventory(InventoryAddModel model, HttpPostedFileBase imagePath)
        {
            if (ModelState.IsValid)
            {
                if (!_inventoryService.IsInventoryCodeExists(model.InventoryCode))
                {
                    model.ImagePath = (string.IsNullOrEmpty(Convert.ToString(imagePath))) ? "" : string.Format("~/InventoryUpload/{0}-{1}", Guid.NewGuid(), imagePath.FileName);

                    var result = _inventoryService.AddInventory(model);
                    if (result > 0)
                    {
                        if (!string.IsNullOrWhiteSpace(model.ImagePath))
                        {
                            imagePath.SaveAs(Server.MapPath(model.ImagePath));
                        }

                        return(RedirectToAction("Index", "InventoryWeb").WithSuccess("Inventarielista är tillagd."));
                    }
                    else
                    {
                        return(View().WithError("Ett fel har uppstått vid tillagd inventarielista."));
                    }
                }
                else
                {
                    return(View().WithError("Inventariekod är redan tillgänglig för en existerande produkt."));
                }
            }
            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <ProductOutputModel> AddProduct(ProductInputModel productModel, CancellationToken cancellationToken)
        {
            var existProduct = await productRepository.Any(e => e.Name.Equals(productModel.Name), cancellationToken);

            if (existProduct)
            {
                throw new System.Exception("O produto informado já existe!");
            }

            var product = mapper.Map <Product>(productModel);

            product.Company = await companyRepository.Get(e => e.Id.Equals(productModel.CompanyId), cancellationToken);

            product.Category = await productTypeRepository.Get(e => e.Id.Equals(productModel.ProductTypeId), cancellationToken);

            var result = await productRepository.Add(product, cancellationToken);

            await inventoryService.AddInventory(result.Id, DEFAULT_INVENTORY_QUANTITY, cancellationToken);

            return(mapper.Map <ProductOutputModel>(result));
        }
Exemplo n.º 3
0
 public Inventory AddInventory([FromBody] Inventory inventory)
 {
     return(inventoryService.AddInventory(inventory));
 }