Пример #1
0
 public IActionResult Seed()
 {
     for (int i = 2; i < 7; i++)
     {
         db.Add(new Court {
             Name = "Court#" + i.ToString(), Adress = "Adress#" + i.ToString(), Description = "Description#" + i.ToString(), Image = "images/" + i.ToString() + ".jpg", Rating = i, RegionId = i % 2 == 0? 1 : 2
         });
         db.SaveChanges();
     }
     return(Ok(new { apiStatus = "successfully_retrieved_products", message = "Successfully seeding Courts", success = true }));
 }
Пример #2
0
 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 }));
     }
 }