public IHttpActionResult CreatePieCategory(PieCategory pieCategory) { if (!ModelState.IsValid) { //throw new HttpResponseException(HttpStatusCode.BadRequest); return(BadRequest("Model data is invalid")); } _context.PieCategories.Add(pieCategory); _context.SaveChanges(); return(Ok(pieCategory)); }
public ActionResult SaveCategory(PieCategory pieCategory) { if (pieCategory.Id == 0) { _context.PieCategories.Add(pieCategory); } else { var catInDb = _context.PieCategories.Single(c => c.Id == pieCategory.Id); catInDb.CName = pieCategory.CName; catInDb.Description = pieCategory.Description; } _context.SaveChanges(); return(RedirectToAction("IndexCategory", "Admin")); }
public ActionResult SaveCategory(PieCategory pieCategory) { if (pieCategory.Id == 0) { HttpResponseMessage response = GlobalVariables.webApiClient.PostAsJsonAsync("CategoryApi", pieCategory).Result; //_context.PieCategories.Add(pieCategory); } else { //var catInDb = _context.PieCategories.Single(c => c.Id == pieCategory.Id); //catInDb.CName = pieCategory.CName; //catInDb.Description = pieCategory.Description; HttpResponseMessage response = GlobalVariables.webApiClient.PutAsJsonAsync($"CategoryApi/{pieCategory.Id}", pieCategory).Result; } //_context.SaveChanges(); return(RedirectToAction("AllCategory", "Admin")); }
public IHttpActionResult UpdatePieCategory(int id, PieCategory pieCategory) { if (!ModelState.IsValid) { //throw new HttpResponseException(HttpStatusCode.BadRequest); return(BadRequest("Model data is invalid")); } var piecatInDb = _context.PieCategories.SingleOrDefault(c => c.Id == id); if (piecatInDb == null) { //throw new HttpResponseException(HttpStatusCode.NotFound); return(NotFound()); } piecatInDb.CName = pieCategory.CName; piecatInDb.Description = pieCategory.Description; _context.SaveChanges(); return(Ok()); }