public IActionResult Add([FromBody] Task Task)
        {
            IActionResult result;
            var           projectId = this.GetProjectId(Task.JalonId);

            if (projectId != 0)
            {
                if (this.Access(projectId))
                {
                    try
                    {
                        this.TaskRepository.Add(Task);
                        this.TaskRepository.SaveChanges();
                        result = Ok(new { Message = "Insertion effectué" });
                    }
                    catch
                    {
                        result = StatusCode(500);
                    }
                }
                else
                {
                    result = Unauthorized();
                }
            }
            else
            {
                result = Unauthorized(new { Message = "Vous n'avez pas les droits" });
            }

            return(result);
        }
        public IActionResult Get(int id)
        {
            IActionResult result;
            Task          Task = TaskRepository.GetById(id);

            if (Task != null)
            {
                var projectId = this.GetProjectId(Task.JalonId);
                if (projectId != 0)
                {
                    if (!this.Access(projectId))
                    {
                        result = Unauthorized(new { Message = "Vous n'avez pas le droit d'accéder à la ressource demander!" });
                    }
                    else
                    {
                        result = Ok(Task);
                    }
                }
                else
                {
                    result = Unauthorized();
                }
            }
            else
            {
                result = NotFound(new { Message = "Tache inexistante!" });
            }
            return(result);
        }
        public IActionResult Start([FromBody] Task Task)
        {
            IActionResult result;
            var           projectId = this.GetProjectId(Task.JalonId);

            if (projectId != 0)
            {
                if (this.Access(projectId))
                {
                    Task UpdateTask = this.TaskRepository.GetById(Task.Id);
                    if (UpdateTask == null)
                    {
                        result = NotFound(new { Message = "La tache n'existe pas" });
                    }
                    else
                    {
                        try
                        {
                            this.TaskRepository.Detach(UpdateTask);
                            if (Task.TaskIdDepend != null)
                            {
                                Task DependTask = this.TaskRepository.GetById(Task.TaskIdDepend.GetValueOrDefault());
                                if (DependTask.DateEndTask != null)
                                {
                                    Task.DateStartTaskReal = DateTime.Now;
                                    this.TaskRepository.Update(Task);
                                    this.TaskRepository.SaveChanges();
                                    result = Ok(new { Message = "Tache commencé" });
                                }
                                else
                                {
                                    result = StatusCode(401);
                                }
                            }
                            else
                            {
                                Task.DateStartTaskReal = DateTime.Now;
                                this.TaskRepository.Update(Task);
                                this.TaskRepository.SaveChanges();
                                result = Ok(new { Message = "Tache commencé" });
                            }
                        }
                        catch
                        {
                            result = StatusCode(500);
                        }
                    }
                }
                else
                {
                    result = Unauthorized();
                }
            }
            else
            {
                result = Unauthorized(new { Message = "Le projet n'éxiste pas" });
            }
            return(result);
        }
Пример #4
0
        protected bool Access(int idProject)
        {
            Project Project = ProjectRepository.GetById(idProject);
            int     userId  = this.GetId();
            bool    result  = true;

            if (Project == null)
            {
                result = false;
            }
            else
            {
                if (Project.Id != userId && !this.IsChief())
                {
                    Jalon Jalon = JalonRepository.getForUser(idProject, userId);
                    if (Jalon == null)
                    {
                        bool         trouver = false;
                        List <Jalon> Jalons  = JalonRepository.GetJalonForProject(idProject);
                        foreach (Jalon aJalon in Jalons)
                        {
                            Task task = TaskRepository.getTaskForUser(aJalon.Id, userId);
                            if (task != null)
                            {
                                trouver = true;
                            }

                            TaskRepository.Detach(task);
                            JalonRepository.Detach(aJalon);
                        }

                        if (!trouver)
                        {
                            result = false;
                        }
                    }
                }

                ProjectRepository.Detach(Project);
            }

            return(result);
        }
        public IActionResult Update([FromBody] Task Task)
        {
            IActionResult result;
            var           projectId = this.GetProjectId(Task.JalonId);

            if (projectId != 0)
            {
                if (this.Access(projectId))
                {
                    Task UpdateTask = this.TaskRepository.GetById(Task.Id);
                    if (UpdateTask == null)
                    {
                        result = NotFound(new { Message = "La tache n'existe pas" });
                    }
                    else
                    {
                        try
                        {
                            this.TaskRepository.Detach(UpdateTask);
                            this.TaskRepository.Update(Task);
                            this.TaskRepository.SaveChanges();
                            result = Ok(new { Message = "Modification effectué" });
                        }
                        catch
                        {
                            result = StatusCode(500);
                        }
                    }
                }
                else
                {
                    result = Unauthorized();
                }
            }
            else
            {
                result = Unauthorized(new { Message = "Le projet n'éxiste pas" });
            }
            return(result);
        }