public bool CreateSessionType(SessionTypeCreate model) { SessionType sessionType = new SessionType() { Name = model.Name, PricePerHour = model.PricePerHour }; using (var db = new ApplicationDbContext()) { db.SessionTypes.Add(sessionType); return(db.SaveChanges() == 1); } }
public ActionResult Create(SessionTypeCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = new SessionTypeService(); if (service.CreateSessionType(model)) { return(RedirectToAction("Index")); } ModelState.AddModelError("", "Session type could not be added"); return(View(model)); }