Ejemplo n.º 1
0
        public IActionResult SaveNewProject(ProjectViewModel model)
        {
            Dal            dal = new Dal();
            Collaborateurs c   = dal.GetCollaborateurs(HttpContext.User.Identity.Name);

            if (ModelState.IsValid)
            {
                var project = new Leaf.DAL.ScaffoldedModels.Projet {
                    Nom = model.ProjectName, Debut = model.StartDate, Echeance = model.EndDate, Client = model.ProjectClient, Responsable = model.ProjectLeader
                };

                bool result = dal.SaveNewProject(project);

                if (result)
                {
                    var returnModel = new ProjectsViewModel
                    {
                        projets = dal.GetProjets(c)
                    };
                    foreach (var projet in returnModel.projets)
                    {
                        projet.ClientNavigation      = dal.GetClient(projet.Client);
                        projet.ResponsableNavigation = dal.GetCollaborateurs(projet.Responsable);
                    }
                    if (c.Id == project.Responsable)
                    {
                        dal.AddNotification(project.Responsable, project.Id, null, "Votre nouveau projet a bien été créé.", DateTime.Now);
                    }
                    else
                    {
                        if (dal.IsProjectManager(c.Mail, project.Id))
                        {
                            dal.AddNotification(project.Responsable, project.Id, null, "Vous avez été assigné à un nouveau projet par son chef :  " + c.Prenom + " " + c.Nom + ".", DateTime.Now);
                        }
                        else
                        {
                            dal.AddNotification(project.Responsable, project.Id, null, "Vous avez été assigné à un nouveau projet par un administrateur.", DateTime.Now);
                        }
                    }

                    return(View("ProjectList", returnModel));
                }
            }
            ;


            model._clients            = dal.GetClients(c);
            model._projectManagerList = dal.getProjectManagers();

            return(View("ProjectCreation", model));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// To prepare the display
        /// </summary>
        /// <param name="id">The id of the project to modify</param>
        /// <returns>A View containing a ProjectViewModel</returns>
        public IActionResult ProjectModification(int?id)
        {
            Dal            dal = new Dal();
            Collaborateurs c   = dal.GetCollaborateurs(HttpContext.User.Identity.Name);

            Leaf.DAL.ScaffoldedModels.Projet projectToModify = dal.GetProjet((int)id);
            projectToModify.ClientNavigation      = dal.GetClient(projectToModify.Client);
            projectToModify.ResponsableNavigation = dal.GetCollaborateurs(projectToModify.Responsable);

            var model = new ProjectViewModel
            {
                Project             = projectToModify,
                ProjectName         = projectToModify.Nom,
                ProjectClient       = projectToModify.Client,
                ProjectLeader       = projectToModify.Responsable,
                StartDate           = projectToModify.Debut,
                EndDate             = projectToModify.Echeance,
                _clients            = dal.GetClients(c),
                _projectManagerList = dal.getProjectManagers()
            };

            return(View(model));
        }