public IActionResult Add(Court model) { try { if (db.Courts.Any(s => s.Id == model.Id)) { var item = db.Courts.FirstOrDefault(s => s.Id == model.Id); item.Name = model.Name; item.Adress = model.Adress; item.Description = model.Description; item.Image = model.Image; item.Rating = model.Rating; item.RegionId = model.RegionId; db.Update(item); db.SaveChanges(); return(Ok(new { model = db.Courts, apiStatus = "successfully_updated", message = "Successfully updated the court", success = true })); } db.Add(model); db.SaveChanges(); return(Ok(new { model = db.Courts, apiStatus = "successfully_added", message = "Successfully added the court", success = true })); } catch (Exception ex) { return(Ok(new { apiStatus = "internal_error_added", message = ex.Message, success = false })); } }
public IActionResult Add(Region model) { try { if (db.Regions.Any(s => s.Id == model.Id)) { var item = db.Regions.FirstOrDefault(s => s.Id == model.Id); item.Name = model.Name; db.Update(item); db.SaveChanges(); return(Ok(new { model = db.Regions, apiStatus = "successfully_updated", message = "Successfully updated the product", success = true })); } db.Add(model); db.SaveChanges(); return(Ok(new { model = db.Regions, apiStatus = "successfully_added", message = "Successfully added the product", success = true })); } catch (Exception ex) { return(Ok(new { apiStatus = "internal_error_added", message = ex.Message, success = false })); } }