public IHttpActionResult Post(WorkoutPlanCreate workoutPlan) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateWorkoutPlanService(); if (!service.CreateWorkoutPlan(workoutPlan)) { return(InternalServerError()); } return(Ok()); }
//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); } }
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); } }
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)); }