Ejemplo n.º 1
0
        public IActionResult Update(int id, [FromBody] ProjectFront project)
        {
            int affectedRows = _projectService.UpdateProject(id, project);

            if (affectedRows == 0)
            {
                return(BadRequest("Invalid input, object invalid"));
            }
            else
            {
                int?[] userIds = new int?[] { project.managerId };
                userIds = userIds.Concat(project.generalsId).ToArray()
                          .Concat(project.developersId).ToArray();
                NMS.SendALLmessage($"Update Issue {project.Name}", $"Update Issue {project.Name}", userIds);

                return(Ok(affectedRows));
            }
        }
        /// <summary>
        /// Create a new project
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public int CreateProject(ProjectFront project)
        {
            ProjectEntity projectEntity = project.ObjectConvert <ProjectEntity>();
            var           projectId     = _projectDao.CreateProject(projectEntity);

            // 新增 UserProjectRelation 的關係
            // manager
            _projectDao.CreateUserProjectRelation(new UserProjectRelationEntity()
            {
                ProjectId          = projectId,
                UserId             = project.managerId,
                ProjectCharactorId = 1  // Manager
            });
            // developer
            if (project.developersId != null)
            {
                foreach (var developerId in project.developersId)
                {
                    _projectDao.CreateUserProjectRelation(new UserProjectRelationEntity()
                    {
                        ProjectId          = projectId,
                        UserId             = developerId,
                        ProjectCharactorId = 2
                    });
                }
            }
            // general
            if (project.generalsId != null)
            {
                foreach (var generalId in project.generalsId)
                {
                    _projectDao.CreateUserProjectRelation(new UserProjectRelationEntity()
                    {
                        ProjectId          = projectId,
                        UserId             = generalId,
                        ProjectCharactorId = 3
                    });
                }
            }

            return(projectId);
        }
        /// <summary>
        /// Update a specific project
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public int UpdateProject(int projectId, ProjectFront project)
        {
            _projectDao.UpdateProject(new ProjectEntity()
            {
                Id = projectId
            }, project.ObjectConvert <ProjectEntity>());

            // 更新 UserProjectRelation
            _projectDao.DeleteRelationByProjectId(projectId);    // 刪除所有關聯

            // 新增 UserProjectRelation 的關係
            // manager
            _projectDao.CreateUserProjectRelation(new UserProjectRelationEntity()
            {
                ProjectId          = projectId,
                UserId             = project.managerId,
                ProjectCharactorId = 1  // Manager
            });
            // developer
            foreach (var developerId in project.developersId)
            {
                _projectDao.CreateUserProjectRelation(new UserProjectRelationEntity()
                {
                    ProjectId          = projectId,
                    UserId             = developerId,
                    ProjectCharactorId = 2
                });
            }
            // general
            foreach (var generalId in project.generalsId)
            {
                _projectDao.CreateUserProjectRelation(new UserProjectRelationEntity()
                {
                    ProjectId          = projectId,
                    UserId             = generalId,
                    ProjectCharactorId = 3
                });
            }

            return(projectId);
        }
Ejemplo n.º 4
0
        public IActionResult Create([FromBody] ProjectFront project)
        {
            int affectedRows = _projectService.CreateProject(project);

            if (affectedRows == 0)
            {
                return(BadRequest("Invalid input, object invalid"));
            }
            else if (affectedRows == -1)
            {
                return(Conflict("An existing item already exist"));
            }
            else
            {
                int?[] userIds = new int?[] { project.managerId };
                userIds = userIds.Concat(project.generalsId).ToArray()
                          .Concat(project.developersId).ToArray();
                NMS.SendALLmessage($"Create Issue {project.Name}", $"Create Issue {project.Name}", userIds);

                return(Ok(affectedRows));
            }
        }