public IActionResult Create() { ViewBag.CategoryID = new SelectList(_categoryService.GetCategories(), "CategoryId", "CategoryName"); InventoryCreateViewModel vm = new InventoryCreateViewModel(); return(View(vm)); }
public async Task <IActionResult> Update(InventoryCreateViewModel vm) { ApplicationUser applicationUser = await _userManager.GetUserAsync(User); string userEmail = applicationUser?.Email; string uniqueFileName = null; if (ModelState.IsValid) { if (vm.Image != null) { string uploadFolder = Path.Combine(_hostingEnvironmentServices.WebRootPath + "\\images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + vm.Image.FileName; string filePath = Path.Combine(uploadFolder, uniqueFileName); vm.Image.CopyTo(new FileStream(filePath, FileMode.Create)); Inventory updatedInventory = new Inventory() { ProductId = vm.ProductId, CategoryId = vm.CategoryId, Name = vm.Name, Description = vm.Description, NetPrice = vm.NetPrice, SalePrice = vm.SalePrice, Quantity = vm.Quantity, Image = uniqueFileName, Active = 1, SaleQuantity = vm.SaleQuantity, RestQuantity = vm.Quantity - vm.SaleQuantity, UpdatedBy = userEmail, UpdatedDate = DateTime.Now }; await _inventoryService.UpdateAsync(updatedInventory); } else { Inventory updatedInventory = new Inventory() { ProductId = vm.ProductId, CategoryId = vm.CategoryId, Name = vm.Name, Description = vm.Description, NetPrice = vm.NetPrice, SalePrice = vm.SalePrice, Quantity = vm.Quantity, Image = vm.ImageURL, Active = 1, SaleQuantity = vm.SaleQuantity, RestQuantity = vm.Quantity - vm.SaleQuantity, UpdatedBy = userEmail, UpdatedDate = DateTime.Now }; await _inventoryService.UpdateAsync(updatedInventory); } } ViewBag.CategoryID = new SelectList(_categoryService.GetCategories(), "CategoryId", "CategoryName", vm.CategoryId); return(RedirectToAction("Details", "Categories", new { id = vm.CategoryId })); }
// GET: Inventorys/Create public async Task <IActionResult> Create() { var vm = new InventoryCreateViewModel() { ShopSelectList = new SelectList(await _bll.Shops.AllAsync(), nameof(Shop.Id), nameof(Shop.ShopName)) }; return(View(vm)); }
// GET: Inventorys/Create public async Task <IActionResult> Create() { var vm = new InventoryCreateViewModel() { ShopSelectList = new SelectList(await _bll.Shops.GetShopByUserShopIdForDropDown(User.GetShopId()), nameof(Shop.Id), nameof(Shop.ShopName)) }; return(View(vm)); }
public async Task <IActionResult> Create(InventoryCreateViewModel vm) { if (ModelState.IsValid) { await _bll.Inventories.AddAsync(vm.Inventory); await _bll.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } vm.ShopSelectList = new SelectList(await _bll.Shops.AllAsync(), nameof(Shop.Id), nameof(Shop.ShopName)); return(View(vm)); }
public IActionResult Create(InventoryCreateViewModel inventoryCreateViewModel) { Item item = new Item(); item.Id = Guid.NewGuid(); item.AccountId = User.FindFirstValue(ClaimTypes.NameIdentifier); item.Name = inventoryCreateViewModel.Name; item.Type = inventoryCreateViewModel.Type; item.Value = inventoryCreateViewModel.Value; _itemRepository.Create(item); return(RedirectToAction("Index", "Inventory")); }
public async Task <IActionResult> Edit(int id, InventoryCreateViewModel vm) { if (id != vm.Inventory.Id) { return(NotFound()); } if (ModelState.IsValid) { _bll.Inventories.Update(vm.Inventory); await _bll.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } vm.ShopSelectList = new SelectList(await _bll.Shops.AllAsync(), nameof(Shop.Id), nameof(Shop.ShopName)); return(View(vm)); }
// GET: Inventorys/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var inventory = await _bll.Inventories.FindAsync(id); if (inventory == null) { return(NotFound()); } var vm = new InventoryCreateViewModel() { Inventory = inventory, ShopSelectList = new SelectList(await _bll.Shops.AllAsync(), nameof(Shop.Id), nameof(Shop.ShopName)) }; return(View(vm)); }
public IActionResult Update(int id) { Inventory inventory = _inventoryService.GetSingle(p => p.ProductId == id); InventoryCreateViewModel vm = new InventoryCreateViewModel { ProductId = inventory.ProductId, CategoryId = inventory.CategoryId, Name = inventory.Name, Description = inventory.Description, NetPrice = inventory.NetPrice, SalePrice = inventory.SalePrice, Quantity = inventory.Quantity, ImageURL = inventory.Image, Active = inventory.Active, SaleQuantity = inventory.SaleQuantity, RestQuantity = inventory.Quantity - inventory.SaleQuantity }; ViewBag.CategoryID = new SelectList(_categoryService.GetCategories(), "CategoryId", "CategoryName", inventory.CategoryId); return(View(vm)); }