public IActionResult Create(CreatePlanViewModel model)
        {
            try {
                foreach (ToDo item in model.AssignedToDos)
                {
                    ToDo currentToDo = listOfToDos.Single(t => t.ID == item.ID);
                    currentToDo.STATUS = item.STATUS;

                    using (SqlConnection sqlConnection = new SqlConnection("Data Source=5SSDHH2;Initial Catalog=JMProjectDB;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"))
                    {
                        using (SqlCommand command = new SqlCommand("CreatePlan", sqlConnection))
                        {
                            command.CommandType = CommandType.StoredProcedure;
                            command.Parameters.Add("@ToDoID", SqlDbType.Int);
                            command.Parameters.Add("@ToDoStatus", SqlDbType.NVarChar, 12);
                            command.Parameters.Add("@ToDoClosed", SqlDbType.DateTime);
                            command.Parameters["@ToDoID"].Value     = currentToDo.ID;
                            command.Parameters["@ToDoStatus"].Value = currentToDo.STATUS;
                            command.Parameters["@ToDoClosed"].Value = currentToDo.CLOSED;
                            sqlConnection.Open();
                            command.ExecuteNonQuery();
                        }
                    }
                }
                return(RedirectToAction("Index"));
            }

            catch (SqlException ex)
            {
                string msg = "Error:";
                msg += ex.Message;
                throw new Exception(msg);
            }
        }
예제 #2
0
        public IActionResult Create()
        {
            var model = new CreatePlanViewModel
            {
                RecipeDetails = combosHelper.GetComboRecipes()
            };

            return(View(model));
        }
예제 #3
0
        public async Task <IActionResult> Create(CreatePlanViewModel model)
        {
            if (ModelState.IsValid)
            {
                var createPlan = new CreatePlan
                {
                    Name         = model.Name,
                    RecipeDetail = await dataContext.RecipeDetails.FirstOrDefaultAsync(m => m.Id == model.RecipeDetailId),
                };
                dataContext.CreatePlans.Add(createPlan);
                await dataContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
        public IActionResult Create(int id)
        {
            ToDoList currentToDoList = listOfToDoLists.Single(t => t.ID == id);

            using (IDbConnection connection = new SqlConnection("Data Source=5SSDHH2;Initial Catalog=JMProjectDB;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"))
            {
                using (connection)
                {
                    DynamicParameters p = new DynamicParameters();
                    p.Add("@ToDoListID", currentToDoList.ID);
                    var listOfAvailableToDos = (List <ToDo>)connection.Query <TaskapaloozaBeta.Models.ToDo>("EXEC GetListOfAvailableToDos @ToDoListID", new { ToDoListID = currentToDoList.ID });

                    CreatePlanViewModel model = new CreatePlanViewModel(currentToDoList, listOfAvailableToDos);

                    return(View(model));
                }
            }
        }
        public ActionResult AddExcerciseToPlan(CreatePlanViewModel cpVM)
        {
            cpVM.plan = int.Parse(Session["planID"].ToString());
            if (ModelState.IsValid)
            {
                using (var dbContext = new Model1())
                {
                    cpVM.exercisesInSession.ExercisesInSessionId = ExercisesInSession.GenerateId();
                    var sessions = dbContext.TrainingSessionsInPlan.Where(s => s.PlanId == cpVM.plan).ToList();
                    if (sessions.Count() != 0)
                    {
                        foreach (var session in sessions)
                        {
                            var tSession = dbContext.TrainingSession.FirstOrDefault(s => s.DayOfTraining == cpVM.day && s.SessionId == session.SessionId);
                            if (tSession != null)
                            {
                                cpVM.exercisesInSession.SessionId = tSession.SessionId;
                            }
                        }
                    }
                    else
                    {
                        var newTrainingSession = new TrainingSession
                        {
                            SessionId     = TrainingSession.GenerateId(),
                            DayOfTraining = cpVM.day
                        };
                        cpVM.exercisesInSession.SessionId = newTrainingSession.SessionId;
                        var newSessionInPlan = new TrainingSessionsInPlan
                        {
                            SessionId = newTrainingSession.SessionId,
                            PlanId    = cpVM.plan
                        };
                        dbContext.TrainingSessionsInPlan.Add(newSessionInPlan);
                        dbContext.TrainingSession.Add(newTrainingSession);
                    }

                    dbContext.ExercisesInSession.Add(cpVM.exercisesInSession);
                    dbContext.SaveChanges();
                }
            }
            return(RedirectToAction("EditPlan", "Trainer", new { planId = cpVM.plan }));
        }