public IHttpActionResult PutRecipe(int id, Recipe recipe) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != recipe.Id_Recipe) { return(BadRequest()); } db.Entry(recipe).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RecipeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutProduct(int id, Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != product.Id_Product) { return(BadRequest()); } db.Entry(product).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> Register(UserModel userModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } IdentityResult result = await _repo.RegisterUser(userModel); IHttpActionResult errorResult = GetErrorResult(result); if (errorResult != null) { return(errorResult); } List l = new List() { Items = "" }; cooker_db.Lists.Add(l); cooker_db.SaveChanges(); UserDetail ud = new UserDetail() { Login = userModel.UserName, Id_List = l.Id_List, Social_Account = false, Admin = false }; cooker_db.Users.Add(ud); cooker_db.SaveChanges(); return(Ok("Created")); }
public IHttpActionResult PutCategory_Main(int id, Category_Main category_Main) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != category_Main.Id_Category_Main) { return(BadRequest()); } db.Entry(category_Main).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!Category_MainExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult DeleteBlackItem(int id_user, int id_product) { Black_Item bi = db.Black_Items.SingleOrDefault(x => x.Id_User == id_user && x.Id_Product == id_product); db.Black_Items.Remove(bi); db.SaveChanges(); return(Ok("Removed")); }