public async Task <IActionResult> AddAddendumItems(int id, [Bind("AddendumDetailId,AddendumId,LotItemId,Quantity")] AddendumDetail addendumDetail) { if (ModelState.IsValid) { addendumDetail.AddendumId = id; _context.Add(addendumDetail); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(AddAddendumItems), new { id })); } var LId = _context.Addendum.Include(a => a.Lot).Where(a => a.AddendumId == id).Select(a => a.LotId).FirstOrDefault(); ViewBag.LId = LId; var result = _context.Lot .Where(a => a.lotId == LId) .Select(x => new { x.lotId, lotDescription = "Lot No - " + x.lotno.ToString() }).OrderBy(a => a.lotId); ViewBag.LotId = new SelectList(result, "lotId", "lotDescription"); var names = _context.AddendumDetail.Include(a => a.Addendum).Where(a => a.Addendum.LotId == (result.Select(b => b.lotId).FirstOrDefault())).Select(a => a.LotItemId).ToArray <int>(); var ItemsList = from item in _context.LotItem where item.lotId == (result.Select(b => b.lotId).FirstOrDefault()) && !names.Contains(item.LotItemId) select item; ViewBag.AddID = id; ViewBag.PPLotItemId = new SelectList(ItemsList, "LotItemId", "ItemName"); return(View(addendumDetail)); }
public async Task <IActionResult> Edit(int id, [Bind("AddendumDetailId,AddendumId,LotItemId,Quantity")] AddendumDetail addendumDetail) { if (id != addendumDetail.AddendumDetailId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(addendumDetail); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AddendumDetailExists(addendumDetail.AddendumDetailId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AddendumId"] = new SelectList(_context.Addendum, "AddendumId", "AddendumId", addendumDetail.AddendumId); ViewData["LotItemId"] = new SelectList(_context.LotItem, "LotItemId", "LotItemId", addendumDetail.LotItemId); return(View(addendumDetail)); }
public IActionResult AddAddendumItems(int id) { var LId = _context.Addendum.Include(a => a.Lot).Where(a => a.AddendumId == id).Select(a => a.LotId).FirstOrDefault(); ViewBag.LId = LId; var result = _context.Lot .Where(a => a.lotId == LId) .Select(x => new { x.lotId, lotDescription = "Lot No - " + x.lotno.ToString() }).OrderBy(a => a.lotId); ViewBag.LotId = new SelectList(result, "lotId", "lotDescription"); var names = _context.AddendumDetail.Include(a => a.Addendum).Where(a => a.Addendum.LotId == (result.Select(b => b.lotId).FirstOrDefault())).Select(a => a.LotItemId).ToArray <int>(); var ItemsList = from item in _context.LotItem where item.lotId == (result.Select(b => b.lotId).FirstOrDefault()) && !names.Contains(item.LotItemId) select item; ViewBag.AddID = id; ViewBag.PPLotItemId = new SelectList(ItemsList, "LotItemId", "ItemName"); AddendumDetail Obj = new AddendumDetail(); Obj.AddendumId = id; return(View(Obj)); }
public async Task <IActionResult> Create([Bind("AddendumDetailId,AddendumId,LotItemId,Quantity")] AddendumDetail addendumDetail) { if (ModelState.IsValid) { _context.Add(addendumDetail); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AddendumId"] = new SelectList(_context.Addendum, "AddendumId", "AddendumId", addendumDetail.AddendumId); ViewData["LotItemId"] = new SelectList(_context.LotItem, "LotItemId", "LotItemId", addendumDetail.LotItemId); return(View(addendumDetail)); }