public IActionResult Post([FromBody] InventoryImage inventory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.InventoryImage.Add(inventory); try { _context.SaveChanges(); } catch (DbUpdateException) { if (InventoryExists(inventory.InventoryImageId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtRoute("GetInventoryImage", new { id = inventory.InventoryImageId }, inventory)); }
public IActionResult Post([FromBody] Geek geek) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var existinUser = from g in _context.Geek where g.UserName == geek.UserName select g; if (existinUser == null) { _context.Geek.Add(geek); } _context.Geek.Add(geek); try { _context.SaveChanges(); } catch (DbUpdateException) { if (GeekExists(geek.GeekId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtRoute("GetGeek", new { id = geek.GeekId }, geek)); }
public IActionResult Post([FromBody] Inventory newInventoryItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Inventory.Add(newInventoryItem); try { _context.SaveChanges(); } catch (DbUpdateException) { if (InventoryExists(newInventoryItem.InventoryId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { return(new StatusCodeResult(StatusCodes.Status418ImATeapot)); } } return(CreatedAtRoute("GetInventory", new { id = newInventoryItem.InventoryId }, newInventoryItem)); }
public IActionResult Post([FromBody] Geek newGeek) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } IQueryable <Geek> existingUser = from geek in _context.Geek where geek.UserName == newGeek.UserName select geek; int userExists = existingUser.Count <Geek>(); if (userExists > 0) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } //actually modifies newGeek to give GeekId a non-null value (property already exists due to ModelState casting) _context.Geek.Add(newGeek); try { _context.SaveChanges(); } catch (DbUpdateException) { if (GeekExists(newGeek.GeekId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { return(new StatusCodeResult(StatusCodes.Status418ImATeapot)); } } return(CreatedAtRoute("GetGeek", new { id = newGeek.GeekId }, newGeek)); }