Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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));
        }