public async Task <IActionResult> Edit(string productCode)
 {
     return(await resiliencyHelper.ExecuteResilient(async() =>
     {
         var model = new InventoryEditViewModel
         {
             Inventory = await inventoryManagementAPI.GetInventoryByProductCode(productCode)
         };
         return View(model);
     }, View("Offline", new InventoryOfflineViewModel())));
 }
Esempio n. 2
0
        private async System.Threading.Tasks.Task editInventoryItem(DisplayItem item)
        {
            var editViewModel = new InventoryEditViewModel(_viewModel.OriginalVendors.ToList(), _viewModel.OriginalCategories.ToList(), item.Tag as InventoryItem);

            editViewModel.ItemSaved += (object sender, EventArgs e) =>
            {
                _viewModel.InventoryItemSaved(item.Tag as InventoryItem, item);
            };
            var page = new InventoryEditPage();

            page.BindingContext = editViewModel;
            await((MainPage)App.Current.MainPage).NavigateTo(page, true);
        }
Esempio n. 3
0
        protected async void Add_Clicked(object sender, EventArgs e)
        {
            var editViewModel = new InventoryEditViewModel(_viewModel.OriginalVendors.ToList(), _viewModel.OriginalCategories.ToList());

            editViewModel.ItemSaved += (object sender2, EventArgs e2) =>
            {
                _viewModel.InventoryItemSaved(sender2 as InventoryItem, null);
            };
            var page = new InventoryEditPage
            {
                BindingContext = editViewModel
            };

            await((MainPage)App.Current.MainPage).NavigateTo(page, true);
        }
        public ActionResult Edit(InventoryEditViewModel formData)
        {
            Product   product   = Product.All(p => p.BrandId == formData.BrandId && p.Description == formData.Description).Single();
            Inventory inventory = new Inventory()
            {
                Id               = formData.Id,
                ProductId        = product.Id,
                PricePaidPerUnit = formData.PricePaidPerUnit,
                UnitsPurchased   = formData.UnitsPurchased,
                UnitsSold        = formData.UnitsSold
            };

            inventory.Update();
            return(RedirectToAction("Display"));
        }
        // GET: Inventories/New
        public ActionResult New()
        {
            var products = _context.Products.ToList();

            var productDtos = new List <ProductDto>();

            foreach (var product in products)
            {
                productDtos.Add(Mapper.Map <Product, ProductDto>(product));
            }

            var inventoryEditViewModel = new InventoryEditViewModel()
            {
                Products         = productDtos,
                InventoryElement = new InventoryElementDto()
            };

            return(View("InventorySave", inventoryEditViewModel));
        }
        public IActionResult Edit(int Id)
        {
            InventoryEditViewModel inventoryEditViewModel = new InventoryEditViewModel();

            if (Id == 0)
            {
                inventoryEditViewModel.InventoryItem          = new Models.InventoryItem();
                inventoryEditViewModel.LocationSelectedId     = 0;
                inventoryEditViewModel.ManufacturerSelectedId = 0;
                inventoryEditViewModel.Locations     = _context.Locations.ToList();
                inventoryEditViewModel.Manufacturers = _context.Manufacturers.ToList();
            }
            else
            {
                inventoryEditViewModel.InventoryItem          = _context.InventoryItems.Where(c => c.Id == Id).Single();
                inventoryEditViewModel.Locations              = _context.Locations.ToList();
                inventoryEditViewModel.Manufacturers          = _context.Manufacturers.ToList();
                inventoryEditViewModel.LocationSelectedId     = inventoryEditViewModel.InventoryItem.LocationId;
                inventoryEditViewModel.ManufacturerSelectedId = inventoryEditViewModel.InventoryItem.Manufacturer.Id;
            }
            return(View(inventoryEditViewModel));
        }
        // GET: Inventories/Edit/{id}
        public ActionResult Edit(int id)
        {
            var products         = _context.Products.ToList();
            var inventoryElement = _context.Inventory.Find(id);

            var productDtos = new List <ProductDto>();

            foreach (var product in products)
            {
                productDtos.Add(Mapper.Map <Product, ProductDto>(product));
            }

            var inventoryElementDto = Mapper.Map <InventoryElement, InventoryElementDto>(inventoryElement);

            var inventoryEditViewModel = new InventoryEditViewModel()
            {
                Products         = productDtos,
                InventoryElement = inventoryElementDto
            };

            return(View("InventorySave", inventoryEditViewModel));
        }
        public ActionResult Edit(int id)
        {
            Inventory inventory = Inventory.GetById(id);
            Product   product   = Product.GetById(inventory.ProductId);

            ViewBag.Categories   = DataLists.Categories();
            ViewBag.Brands       = DataLists.ProductBrandsWithDescription();
            ViewBag.Descriptions = DataLists.ProductDescription(product.BrandId);

            InventoryEditViewModel model = new InventoryEditViewModel()
            {
                Id               = inventory.Id,
                BrandId          = product.BrandId,
                Description      = product.Description,
                PricePaidPerUnit = inventory.PricePaidPerUnit,
                UnitsPurchased   = inventory.UnitsPurchased,
                UnitsSold        = inventory.UnitsSold,
                CategoryId       = product.CategoryId
            };

            return(View(model));
        }
        // GET: Inventories/Save
        public ActionResult Save(InventoryEditViewModel inventoryEditViewModel)
        {
            var inventoryElementDto = inventoryEditViewModel.InventoryElement;

            if (!ModelState.IsValid)
            {
                var invalidInventoryElement = new InventoryElement()
                {
                    ProductId = inventoryElementDto.ProductId,
                    Amount    = inventoryElementDto.Amount,
                };
                return(View("InventorySave", invalidInventoryElement));
            }

            if (inventoryElementDto.Id == 0)
            {
                var inventoryProduct = _context.Inventory.SingleOrDefault(i => i.ProductId == inventoryElementDto.ProductId);
                if (inventoryProduct != null)
                {
                    inventoryProduct.Amount += inventoryElementDto.Amount;
                }
                else
                {
                    _context.Inventory.Add(Mapper.Map <InventoryElementDto, InventoryElement>(inventoryElementDto));
                }
            }
            else
            {
                var inventoryEntity = _context.Inventory.Find(inventoryElementDto.Id);
                inventoryEntity.Amount    = inventoryElementDto.Amount;
                inventoryEntity.ProductId = inventoryElementDto.ProductId;
                inventoryEntity.Product   = Mapper.Map <ProductDto, Product>(inventoryElementDto.Product);
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "Inventory"));
        }
        public async Task <IActionResult> Edit([FromForm] InventoryEditViewModel inputModel)
        {
            if (ModelState.IsValid)
            {
                return(await resiliencyHelper.ExecuteResilient(async() =>
                {
                    try
                    {
                        var command = new UpdateInventory(Guid.NewGuid(),
                                                          Guid.NewGuid(),
                                                          inputModel.Inventory.ProductCode,
                                                          inputModel.Inventory.Description,
                                                          inputModel.Inventory.Quantity,
                                                          inputModel.Inventory.UnitPrice);

                        await inventoryManagementAPI.UpdateInventory(command);
                    }
                    catch (ApiException ex)
                    {
                        if (ex.StatusCode == HttpStatusCode.Conflict)
                        {
                            var content = await ex.GetContentAsAsync <InventoryRuleViolation>();
                            inputModel.Error = content.ErrorMessage;

                            return View("Edit", inputModel);
                        }
                    }

                    return RedirectToAction("Index");
                }, View("Offline", new InventoryOfflineViewModel())));
            }
            else
            {
                return(View("Edit", inputModel));
            }
        }