public int CreateWorkout(WorkoutCreate model) { using (var ctx = new ApplicationDbContext()) { var thing = ctx .KJPUser .First(e => e.OwnerId == _userId); var entity = new Workout() { UserId = thing.UserId, WorkoutName = model.WorkoutName, Created = DateTimeOffset.Now, }; ctx.Workouts.Add(entity); if (ctx.SaveChanges() == 1) { return(entity.WorkoutId); } return(-1); } }
//Create new workout public bool CreateWorkout(WorkoutCreate model) { //Error Handling using (var ctx = new ApplicationDbContext()) { var workoutPlanIds = ctx.WorkoutPlans.Where(w => w.OwnerId == _userId).Select(w => w.WorkoutPlanId); if (workoutPlanIds.Contains(model.WorkoutPlanId)) { var entity = new Workout() { Title = model.Title, OwnerId = _userId, WorkoutPlanId = model.WorkoutPlanId }; ctx.Workouts.Add(entity); return(ctx.SaveChanges() == 1); } else { return(false); } } }
public IHttpActionResult Post(WorkoutCreate workout) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var Service = CreateWorkoutService(); if (!Service.CreateWorkout(workout)) { return(InternalServerError()); } return(Ok("Workout successfully Created")); }
public bool CreateWorkout(WorkoutCreate model) { var entity = new Workout { UserID = _userID, WorkoutName = model.WorkoutName, Workout_Description = model.Workout_Description, CreatedUtc = DateTimeOffset.UtcNow }; using (var ctx = new ApplicationDbContext()) { ctx.Workouts.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateWorkout(WorkoutCreate model) { var entity = new Workout() { UserId = _userId, WorkoutTitle = model.WorkoutTitle, WorkoutType = model.WorkoutType, WorkoutDetails = model.WorkoutDetails, CreatedUtc = DateTimeOffset.Now, }; using (var ctx = new ApplicationDbContext()) { ctx.Workout.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(WorkoutCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateWorkoutService(); if (service.CreateWorkout(model)) { TempData["SaveResult"] = "Workout created successfully."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Could not create workout"); return(View(model)); }
public ActionResult Create(WorkoutCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateWorkoutService(); if (service.CreateWorkout(model)) { TempData["SaveResult"] = "Your workout was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Workout could not be created"); return(View(model)); }
public bool CreateWorkout(WorkoutCreate model) { var entity = new Workout() { OwnerId = _userId, NameOfWorkout = model.NameOfWorkout, ExerciseId = model.ExerciseId, TrainerId = model.TrainerId, DayOfWorkout = model.DayOfWorkout, Duration = model.Duration, Day = model.Day }; using (var ctx = new ApplicationDbContext()) { ctx.Workouts.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(WorkoutCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateWorkoutService(); var thing = service.CreateWorkout(model); if (thing != -1) { TempData["SaveResult"] = "Workout Created."; return(RedirectToAction("AddExerciseToWorkout", "Exercise", new { id = thing })); } ; ModelState.AddModelError("", "Workout could not be created."); return(View(model)); }