예제 #1
0
        public Project Edit([FromBody] FromAngularProject p)
        {
            var project = this.projectService.GetById(p.id);

            project.Name      = p.name;
            project.Assignees = new List <string>();

            foreach (var user in p.users)
            {
                if (user.Length > 0)
                {
                    var account = this.accountService.GetByProperty("username", user)[0];
                    if (account != null)
                    {
                        project.Assignees.Add(account.Id);
                        project.Assignees         = project.Assignees.Distinct().ToList();
                        project.NumberOfAssignees = project.Assignees.Count();
                        if (account.AssignedProjects == null)
                        {
                            account.AssignedProjects = new List <string>();
                        }
                        account.AssignedProjects.Add(project.Id);
                        account.AssignedProjects = account.AssignedProjects.Distinct().ToList();
                        this.accountService.Update(account.Id, account);
                    }
                }
            }
            this.projectService.Update(project.Id, project);
            return(this.projectService.GetById(project.Id));
        }
예제 #2
0
        public void Create([FromBody] FromAngularProject p)
        {
            var project = new Project();

            project.Name      = p.name;
            project.Assignees = new List <string>();
            var date = DateTime.UtcNow;

            project.DateOfCreation = date;
            project.Tasks          = new List <string>();
            this.projectService.Create(project);

            project = this.projectService.GetAll().Where(a => a.DateOfCreation.Date.Equals(date.Date) && a.DateOfCreation.Hour.Equals(date.Hour) && a.DateOfCreation.Minute.Equals(date.Minute) && a.DateOfCreation.Second.Equals(date.Second)).FirstOrDefault();

            if (project == null)
            {
                return;
            }

            foreach (var user in p.users)
            {
                if (user.Length > 0)
                {
                    var account = this.accountService.GetByProperty("username", user)[0];
                    if (account != null)
                    {
                        project.Assignees.Add(account.Id);
                        project.Assignees         = project.Assignees.Distinct().ToList();
                        project.NumberOfAssignees = project.Assignees.Count();
                        if (account.AssignedProjects == null)
                        {
                            account.AssignedProjects = new List <string>();
                        }
                        account.AssignedProjects.Add(project.Id);
                        account.AssignedProjects = account.AssignedProjects.Distinct().ToList();
                        this.accountService.Update(account.Id, account);
                    }
                }
            }
            this.projectService.Update(project.Id, project);
        }
예제 #3
0
        public void Delete([FromBody] FromAngularProject project)
        {
            var proj = this.projectService.GetById(project.id);

            var connectedAccounts = proj.Assignees;
            var connectedTasks    = proj.Tasks;

            foreach (var acc in connectedAccounts)
            {
                var account = this.accountService.GetById(acc);
                var a       = account.AssignedProjects.Where(ap => ap.Equals(project.id)).FirstOrDefault();
                account.AssignedProjects.Remove(a);
                this.accountService.Update(account.Id, account);
            }

            foreach (var t in connectedTasks)
            {
                var task     = this.taskService.GetById(t);
                var subtasks = task.SubTasksIds;
                var comments = task.Comments;

                foreach (var st in subtasks)
                {
                    this.subTaskService.Remove(st);
                }

                foreach (var com in comments)
                {
                    this.commentService.Remove(com);
                }

                this.taskService.Remove(task.Id);
            }

            this.projectService.Remove(project.id);
        }