public bool CreateWorkout(WorkoutsCreate model) { var entity = new Workouts() { UserId = _userId, Name = model.Name, // Ratings = model.Ratings, CreatedUtc = DateTimeOffset.Now, }; using (var ctx = new ApplicationDbContext()) { ctx.Workouts.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(WorkoutsCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateWorkoutsService(); if (service.CreateWorkout(model)) { TempData["SaveResult"] = "Your Workout was Created. Are you ready to design it?"; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Workout could not be created."); return(View(model)); }