public async Task <IActionResult> EditCategory(int id, Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != category.ID) { return(BadRequest()); } category.UpdatedDate = DateTime.Now; category.UpdatedBy = User.Identity.Name; _context.Entry(category).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task<IActionResult> EditLocation(int id, Location location) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != location.ID) { return BadRequest(); } location.UpdatedDate = DateTime.Now; _context.Entry(location).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LocationExists(id)) { return NotFound(); } else { throw; } } return NoContent(); }
public async Task <bool> MoveItem(MovementItem item, int locationId) { item.UpdatedDate = DateTime.Now; item.IsMoved = true; _context.Entry(item).State = EntityState.Modified; MovementLog log = new MovementLog { AssetID = item.AssetID, LocationID = locationId, MovedBy = User.Identity.Name, CreatedBy = User.Identity.Name, CreatedDate = DateTime.Now }; _context.MovementLog.Add(log); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovementItemExists(item.ID)) { return(false); } else { throw; } } return(true); }
public IActionResult PutCategory([FromRoute] int id, [FromBody] Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != category.ID) { return(BadRequest()); } _context.Entry(category).State = EntityState.Modified; try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }