public bool CreateGym(GymCreate model) { var entity = new Gym() { Name = model.Name, MonthlyCost = model.MonthlyCost, Hours = model.Hours, Description = model.Description, Address = model.Address, Phone = model.Phone, Website = model.Website, Size = model.Size, Equipment = model.Equipment, LockerRoom = model.LockerRoom, Classes = model.Classes, PersonalTraining = model.PersonalTraining, AdditionalInfo = model.AdditionalInfo, CityId = model.CityId }; using (var ctx = new ApplicationDbContext()) { ctx.Gyms.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(GymCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = new GymService(); if (service.CreateGym(model)) { TempData["SaveResult"] = "Gym has been successfully added!"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Gym could not be added."); return(View(model)); }