public async Task <IActionResult> Edit(Guid id, [Bind("SelectedRackID,Edition,Created,OwnerID,ID,RackIndexX,RackIndexY,RackIndexZ,Name,Description")] BinViewModel binViewModel) { if (id != binViewModel.ID) { return(NotFound()); } Bin bin = binViewModel.ToBin(); if (ModelState.IsValid) { try { bin.IncrementEdition(); bin.Rack = await _context.BinRack.FindAsync(binViewModel.SelectedRackID); _context.Update(bin); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PartsBinExists(bin.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(bin)); }
public async Task <IActionResult> Create([Bind("RackIndexX,RackIndexY,RackIndexZ,Name,Description,SelectedRackID")] BinViewModel binViewModel) { Bin bin = binViewModel.ToBin(); if (ModelState.IsValid) { bin.Rack = await _context.BinRack.FindAsync(binViewModel.SelectedRackID); // Assign to the current user IdentityUser currUser = await _userManager.GetUserAsync(User); if (null != currUser) { bin.OwnerID = currUser.Id; } _context.Add(bin); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(bin)); }