コード例 #1
0
        public bool CreateWorkoutType(WorkoutTypeCreate model)
        {
            var entity =
                new WorkoutType()
            {
                UserId = _userId,
                Type   = model.Type,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.WorkoutType.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #2
0
        public ActionResult Create(WorkoutTypeCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateWorkoutTypeService();

            if (service.CreateWorkoutType(model))
            {
                TempData["SaveResult"] = "New Exercise Type created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Exercise Type could not be created");
            return(View(model));
        }