public async Task <IHttpActionResult> PostStockHasItem(StockHasItem stockHasItem, int loggedId, string sessionKey) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Constants.VerifyUserErrors error = AuthHandler.VerifyUserSession(sessionKey, loggedId, db); if (error == Constants.VerifyUserErrors.OK) { db.StockHasItems.Add(stockHasItem); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (StockHasItemExists(stockHasItem.StockID, stockHasItem.ItemID)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = stockHasItem.StockID }, stockHasItem)); } return(StatusCode(CommonMethods.StatusCodeReturn(error))); }
public async Task <IHttpActionResult> DeleteStockHasItem(int id, int loggedId, string sessionKey) { Constants.VerifyUserErrors error = AuthHandler.VerifyUserSession(sessionKey, loggedId, db); StockHasItem stockHasItem = await db.StockHasItems.FindAsync(id); if (error == Constants.VerifyUserErrors.OK) { if (stockHasItem == null) { return(NotFound()); } db.StockHasItems.Remove(stockHasItem); await db.SaveChangesAsync(); return(Ok(stockHasItem)); } return(StatusCode(CommonMethods.StatusCodeReturn(error))); }
public async Task <IHttpActionResult> PutStockHasItem(int stockID, int itemID, StockHasItem stockHasItem, int loggedId, string sessionKey) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (stockID != stockHasItem.StockID || itemID != stockHasItem.ItemID) { return(BadRequest()); } Constants.VerifyUserErrors error = AuthHandler.VerifyUserSession(sessionKey, loggedId, db); if (error == Constants.VerifyUserErrors.OK) { db.Entry(stockHasItem).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StockHasItemExists(stockID, itemID)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); } return(StatusCode(CommonMethods.StatusCodeReturn(error))); }