public async Task <IActionResult> Create(int stockClsId, [Bind("StockClsId,StockItemId,StockItemName,Flg,Rtp,Rtt")] DeptStockItemModel deptStockItemModel) { ViewBag.StockClassName = _context.DeptStockClasses.Find(stockClsId).StockClsName; // Get Login User's details. var ur = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault(); // Set values. deptStockItemModel.Rtp = ur.Id; deptStockItemModel.Rtt = DateTime.Now; /* Set item id. */ var lastItem = _context.DeptStockItems.Where(d => d.StockClsId == stockClsId); if (lastItem.Count() == 0) { // If the class hasn't any item. var lastItemId = 1; deptStockItemModel.StockItemId = lastItemId; } else { var lastItemId = lastItem.OrderByDescending(i => i.StockItemId).First().StockItemId; deptStockItemModel.StockItemId = lastItemId + 1; } if (ModelState.IsValid) { _context.Add(deptStockItemModel); await _context.SaveChangesAsync(); return(RedirectToAction("Index", new { StockClsId = stockClsId })); } return(View(deptStockItemModel)); }
// GET: Admin/DeptStockItem/Create public IActionResult Create(int stockClsId) { ViewBag.StockClassName = _context.DeptStockClasses.Find(stockClsId).StockClsName; // Set default value. DeptStockItemModel deptStockItemModel = new DeptStockItemModel() { StockClsId = stockClsId, Flg = "Y" }; return(View(deptStockItemModel)); }
public async Task <IActionResult> Edit(int stockClsId, int stockItemId, [Bind("StockClsId,StockItemId,StockItemName,Flg,Rtp,Rtt")] DeptStockItemModel deptStockItemModel) { ViewBag.StockClassName = _context.DeptStockClasses.Find(stockClsId).StockClsName; // Get Login User's details. var ur = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault(); deptStockItemModel.Rtp = ur.Id; deptStockItemModel.Rtt = DateTime.Now; if (stockClsId != deptStockItemModel.StockClsId || stockItemId != deptStockItemModel.StockItemId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(deptStockItemModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DeptStockItemModelExists(deptStockItemModel.StockClsId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index", new { StockClsId = stockClsId })); } return(View(deptStockItemModel)); }