public IHttpActionResult Post(WorkoutPlanCreate workoutPlan)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateWorkoutPlanService();

            if (!service.CreateWorkoutPlan(workoutPlan))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Example #2
0
        //CREATE A NEW WORKOUT PLAN
        public bool CreateNewWorkoutPlan(WorkoutPlanCreate model)
        {
            var entity =
                new WorkoutPlan()
            {
                Title          = model.Title,
                DateCreatedUtc = DateTimeOffset.Now,
                OwnerId        = _userId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.WorkoutPlans.Add(entity);

                return(ctx.SaveChanges() == 1);
            }
        }
Example #3
0
        public bool CreateWorkoutPlan(WorkoutPlanCreate model)
        {
            var entity =
                new WorkoutPlan
            {
                CreatedBy   = _userId.ToString(),
                PlanName    = model.PlanName,
                Intensity   = model.Intensity,
                ProgramType = (Data.WorkoutType)model.ProgramType
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.WorkoutPlans.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #4
0
        public ActionResult Create(WorkoutPlanCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            WorkoutPlanService service = CreateWorkoutPlanService();

            if (service.CreateNewWorkoutPlan(model))
            {
                TempData["SaveResult"] = "Your Workout Plan has been created";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Workout Plan was not created");
            return(View(model));
        }