示例#1
0
        public IActionResult ModifyTask(TaskViewModel model, int?projectId, int?taskId)
        {
            Dal dal = new Dal();

            string validationMesg = dal.VerifyNewTask((int)projectId);

            Collaborateurs c = dal.GetCollaborateurs(HttpContext.User.Identity.Name);

            List <Collaborateurs> listCollaborator          = dal.AllCollaborateurs;
            List <Tache>          listEligiblePreviousTasks = dal.GetPotentialPreviousTasks((int)projectId, new List <int>(), (model.SuperTache == null ? -1 : model.SuperTache));

            model._collaboratorList      = listCollaborator;
            model._EligiblePreviousTasks = listEligiblePreviousTasks;

            //Verification
            if (!(validationMesg == ""))
            {
                model.ValidationErrorMessage = validationMesg;
                model._collaboratorList      = listCollaborator;
                model._EligiblePreviousTasks = listEligiblePreviousTasks;
                return(View("TaskCreation", model));
            }

            if (ModelState.IsValid)
            {
                if (model.StartDate == null)
                {
                    model.StartDate = (DateTime)dal.GetTache((int)taskId).Debut;
                }

                if (model.EndDate == null)
                {
                    model.EndDate = (DateTime)dal.GetTache((int)taskId).Fin;
                }

                Tache newTask = new Leaf.DAL.ScaffoldedModels.Tache
                {
                    Id              = (int)taskId,
                    Nom             = model.TaskName,
                    Description     = model.TaskDescription,
                    Debut           = model.StartDate,
                    Fin             = model.EndDate,
                    ChargeConsommee = 0,
                    ChargeEstimee   = model.ChargeEstimee,
                    Progres         = model.Progres,
                    IdProj          = (int)projectId,
                    CollabId        = model.CollabId,
                    SuperTache      = model.SuperTache,
                };

                //Save the new task and the associated previous tasks
                List <int> previousTaskId = new List <int>();
                if (model.DependsMod != null)
                {
                    foreach (var pt in model.DependsMod)
                    {
                        previousTaskId.Add(pt);
                    }
                }

                int?newTaskID = dal.ModifyTask(newTask, previousTaskId);

                if (newTaskID != null)
                {
                    Projet projectToDisplay = dal.GetProjet((int)projectId);
                    projectToDisplay.ClientNavigation      = dal.GetClient(projectToDisplay.Client);
                    projectToDisplay.ResponsableNavigation = dal.GetCollaborateurs(projectToDisplay.Responsable);

                    projectToDisplay.Tache = dal.GetTaskByProjects(projectToDisplay.Id, c.Id);

                    bool IsProjectManagerTemp = dal.IsProjectManager(HttpContext.User.Identity.Name, projectToDisplay.Id);

                    ProjectViewModel project = new ProjectViewModel
                    {
                        Project          = projectToDisplay,
                        IsProjectManager = IsProjectManagerTemp
                    };

                    /*
                     * if(c.Id == newTask.CollabId)
                     * {
                     *  newTask.IdProjNavigation = dal.GetProjet(newTask.IdProj);
                     *  dal.AddNotification(newTask.IdProjNavigation.Responsable, newTask.IdProj, newTaskID, c.Prenom + " " + c.Nom + "a mis à jour une de ses tâches.", DateTime.Now);
                     * }
                     * else if (IsProjectManagerTemp)
                     * {
                     *  dal.AddNotification(newTask.CollabId, newTask.IdProj, newTaskID, "Une de vos tâche a été modifiée par le responsable de projet.", DateTime.Now);
                     * }
                     * else
                     * {
                     *  dal.AddNotification(newTask.CollabId, newTask.IdProj, newTaskID, "Une de vos tâche a été modifiée par l'administrateur.", DateTime.Now);
                     * }
                     */
                    return(View("../Projects/Project", project));
                }
            }

            var collaborateurs = dal.GetCollaborateurs(c.Id);

            model.ProjectId              = (int)projectId;
            model.TaskName               = "";
            model.StartDate              = DateTime.Now;
            model.EndDate                = DateTime.Now;
            model._collaboratorList      = listCollaborator;
            model._EligiblePreviousTasks = listEligiblePreviousTasks;

            return(View("TaskCreation", model));
        }
示例#2
0
        public IActionResult SaveNewTask(TaskViewModel model, int?projectId)
        {
            Dal dal = new Dal();

            string validationMesg = dal.VerifyNewTask((int)projectId);

            Collaborateurs c = dal.GetCollaborateurs(HttpContext.User.Identity.Name);

            List <Collaborateurs> listCollaborator          = dal.AllCollaborateurs;
            List <Tache>          listEligiblePreviousTasks = dal.GetPotentialPreviousTasks((int)projectId, new List <int>(), (model.SuperTache == null ? -1 : model.SuperTache));

            model._collaboratorList      = listCollaborator;
            model._EligiblePreviousTasks = listEligiblePreviousTasks;

            //Verification
            if (!(validationMesg == ""))
            {
                model.ValidationErrorMessage = validationMesg;
                model._collaboratorList      = listCollaborator;
                model._EligiblePreviousTasks = listEligiblePreviousTasks;
                return(View("TaskCreation", model));
            }

            if (ModelState.IsValid)
            {
                Tache newTask = new Leaf.DAL.ScaffoldedModels.Tache
                {
                    Nom             = model.TaskName,
                    Description     = model.TaskDescription,
                    Debut           = model.StartDate,
                    Fin             = model.EndDate,
                    ChargeConsommee = 0,
                    ChargeEstimee   = model.ChargeEstimee,
                    Progres         = model.Progres,
                    IdProj          = (int)projectId,
                    CollabId        = model.CollabId,
                    SuperTache      = model.SuperTache,
                };

                //Save the new task and the associated previous tasks
                int?newTaskID = dal.SaveNewTask(newTask, model.Depends);

                if (newTaskID != null)
                {
                    Projet projectToDisplay = dal.GetProjet((int)projectId);
                    projectToDisplay.ClientNavigation      = dal.GetClient(projectToDisplay.Client);
                    projectToDisplay.ResponsableNavigation = dal.GetCollaborateurs(projectToDisplay.Responsable);

                    projectToDisplay.Tache = dal.GetTaskByProjects(projectToDisplay.Id, c.Id);

                    bool IsProjectManagerTemp = dal.IsProjectManager(HttpContext.User.Identity.Name, projectToDisplay.Id);

                    ProjectViewModel project = new ProjectViewModel
                    {
                        Project          = projectToDisplay,
                        IsProjectManager = IsProjectManagerTemp
                    };

                    /*
                     * dal.AddNotification(newTask.CollabId, newTask.IdProj, newTaskID, "Une nouvelle tâche vous a été attribuée.", DateTime.Now);
                     * if (!IsProjectManagerTemp)
                     * {
                     *  dal.AddNotification(newTask.IdProjNavigation.Responsable, newTask.IdProj, newTaskID, "Une nouvelle tâche a été attribuée à un de vos projet.", DateTime.Now);
                     * }
                     */
                    return(View("../Projects/Project", project));
                }
            }

            var collaborateurs = dal.GetCollaborateurs(c.Id);

            model.ProjectId              = (int)projectId;
            model.TaskName               = "";
            model.StartDate              = DateTime.Now;
            model.EndDate                = DateTime.Now;
            model._collaboratorList      = listCollaborator;
            model._EligiblePreviousTasks = listEligiblePreviousTasks;

            return(View("TaskCreation", model));
        }