public IHttpActionResult PutCustomPizza(int id, CustomPizzaVM customPizzaVM) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != customPizzaVM.Id) { return(BadRequest()); } if (customPizzaVM.UserId != user.UserId) { return(Unauthorized()); } var customPizza = map.CustomPizzaRepo.RetrieveById(id); var tempCP = map.Map(customPizzaVM); customPizza.CustIngredients = tempCP.CustIngredients; map.CustomPizzaRepo.Update(customPizza); try { map.CustomPizzaRepo.Save(); } catch (DbUpdateConcurrencyException) { if (!CustomPizzaExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostCustomPizza(CustomPizzaVM customPizzaVM) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (customPizzaVM.UserId != user.UserId) { return(Unauthorized()); } // All good. Map and insert. var customPizza = map.Map(customPizzaVM); map.CustomPizzaRepo.Insert(customPizza); map.CustomPizzaRepo.Save(); //map.CustIngredientsRepo.Insert(customPizza.CustIngredients); //map.CustIngredientsRepo.Save(); return(CreatedAtRoute("DefaultApi", new { id = customPizza.Id }, customPizza)); }