public async Task <IActionResult> Edit(int id, [Bind("ReppID,Name,Description")] REPP rEPP) { if (id != rEPP.ReppID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(rEPP); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!REPPExists(rEPP.ReppID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(rEPP)); }
public async Task <IActionResult> PutREPP(int id, REPP rEPP) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != rEPP.ReppID) { return(BadRequest()); } _context.Entry(rEPP).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!REPPExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private async Task AddItemAsync(DeliveryModelView item) { REPP ReppExist = await GetInfoOfReppAsync(item); await AddDeliveryAsync(item, ReppExist); await AddQuantityToStockAsync(item, ReppExist); }
private async Task AddDeliveryAsync(DeliveryModelView item, REPP ReppExist) { Delivery delivery = new Delivery() { Brand = item.Brand, ReppID = ReppExist.ReppID, LotID = item.LotID, Description = item.Description, Quantity = item.Quantity, Unit = item.Unit }; _context.Deliveries.Add(delivery); await _context.SaveChangesAsync(); }
public async Task <IActionResult> Create([Bind("ReppID,Name,Description")] REPP rEPP) { if (ModelState.IsValid) { _context.Add(rEPP); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(rEPP)); }
public async Task <IActionResult> PostREPP(REPP rEPP) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.REPPS.Add(rEPP); await _context.SaveChangesAsync(); return(Ok()); }
private async Task <REPP> GetInfoOfReppAsync(DeliveryModelView item) { REPP reference = _context.REPPS.Find(item.ReppID); REPP repp = new REPP() { Name = reference.Name }; REPP ReppExist = _context.REPPS.ToList().Find(x => x.Name == repp.Name); if (ReppExist == null) { _context.REPPS.Add(repp); await _context.SaveChangesAsync(); } ReppExist = _context.REPPS.ToList().Find(x => x.Name == repp.Name); return(ReppExist); }
private async Task AddQuantityToStockAsync(DeliveryModelView item, REPP ReppExist) { Stock stockExist = _context.Stock.ToList().Find(x => x.ReppID == ReppExist.ReppID && x.ColorName == item.ColorName && x.SizeName == item.SizeName); if (stockExist == null) { _context.Stock.Add(new Stock() { ReppID = ReppExist.ReppID, Quantity = item.Quantity, ColorName = item.ColorName, SizeName = item.SizeName }); await _context.SaveChangesAsync(); } else { var stock = _context.Stock.ToList().Find(x => x.StockID == stockExist.StockID); stock.Quantity += item.Quantity; await _context.SaveChangesAsync(); } }