Пример #1
0
        public async Task <int> AddProjectMember(int projectId, int userId, int roleId, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            var project = await _projectRepository.GetById(projectId, cancellationToken);

            if (project == null)
            {
                throw new ProjectNotFoundException(projectId);
            }

            var user = await _userRepository.GetById(userId, cancellationToken);

            if (user == null)
            {
                throw new UserNotFoundException(userId);
            }

            var projectMemberByProjectSpec = new ProjectMemberFilterSpecification(projectId, userId);
            var projectMember = await _projectMemberRepository.GetSingleBySpec(projectMemberByProjectSpec, cancellationToken);

            if (projectMember != null)
            {
                projectMember.ProjectMemberRoleId = roleId;
                await _projectMemberRepository.Update(projectMember, cancellationToken);

                return(projectMember.Id);
            }

            var newProjectMember = new ProjectMember {
                ProjectId = projectId, UserId = userId, ProjectMemberRoleId = roleId
            };

            return(await _projectMemberRepository.Create(newProjectMember, cancellationToken));
        }
Пример #2
0
        public ActionResult CreateProjectMember(ProjectMember projectMember)
        {
            if (projectMember.Id > 0)
            {
                var selectedProjectMember = _projectMemberRepository.Get(projectMember.Id);

                if (selectedProjectMember != null)
                {
                    selectedProjectMember.ProjectMemberRoleId = projectMember.ProjectMemberRoleId;
                    selectedProjectMember.Billing             = projectMember.Billing;
                    selectedProjectMember.Rate            = projectMember.Rate;
                    selectedProjectMember.EmployeeId      = projectMember.EmployeeId;
                    selectedProjectMember.UpdatedByUserId = WebUser.Id;
                    selectedProjectMember.MemberStatus    = projectMember.MemberStatus;
                    _projectMemberRepository.Update(selectedProjectMember);
                    _unitOfWork.Commit();
                    return(RedirectToAction("Details", "Projects", new { Id = projectMember.ProjectId }));
                }
            }
            else
            {
                if (ModelState.IsValid)
                {
                    var alreadyMember = _projectMemberRepository.GetBy(i => i.EmployeeId == projectMember.EmployeeId && i.ProjectId == projectMember.ProjectId);

                    if (alreadyMember == null)
                    {
                        projectMember.CreatedByUserId = WebUser.Id;
                        _projectMemberRepository.Create(projectMember);
                        _unitOfWork.Commit();

                        return(RedirectToAction("Details", "Projects", new { Id = projectMember.ProjectId }));
                    }
                    else
                    {
                        return(Json(false));
                    }
                }
            }
            return(View(projectMember));
        }
Пример #3
0
        public ActionResult Update(ProjectMember vm)
        {
            ApiResult <ProjectMember> apiResult;

            if (ModelState.IsValid)
            {
                if (vm.Id > 0)
                {
                    apiResult = TryExecute(() =>
                    {
                        var project                 = _projectMemberRepository.Get(vm.Id);
                        project.EmployeeId          = vm.EmployeeId;
                        project.Rate                = vm.Rate;
                        project.ProjectMemberRoleId = vm.ProjectMemberRoleId;
                        project.ProjectId           = vm.ProjectId;
                        project.Billing             = vm.Billing;
                        project.UpdatedByUserId     = WebUser.Id;
                        project.MemberStatus        = vm.MemberStatus;
                        project.UpdatedOn           = DateTime.UtcNow;

                        _projectMemberRepository.Update(project);
                        _unitOfWork.Commit();
                        return(project);
                    }, "ProjectMember updated sucessfully");
                }
                else
                {
                    apiResult = TryExecute(() =>
                    {
                        var newProject = new ProjectMember
                        {
                            EmployeeId          = vm.EmployeeId,
                            Rate                = vm.Rate,
                            ProjectMemberRoleId = vm.ProjectMemberRoleId,
                            ProjectId           = vm.ProjectId,
                            Billing             = vm.Billing,
                            MemberStatus        = vm.MemberStatus,
                            CreatedByUserId     = WebUser.Id
                        };
                        _projectMemberRepository.Create(newProject);
                        _unitOfWork.Commit();
                        return(newProject);
                    }, "ProjectMember created sucessfully");
                }
            }
            else
            {
                apiResult = ApiResultFromModelErrors <ProjectMember>();
            }

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        public async Task <ProjectMemberDTO> EditAsync(ProjectMemberDTO model)
        {
            var entity = await _projectMemberRepository.GetByIdAsync(model.ProjectId);

            if (entity == null)
            {
                throw new Exception("Project member not found");
            }

            entity.ProjectId = model.ProjectId;
            entity.UserId    = model.UserId;
            entity.Role      = model.Role;
            entity.JoinDate  = model.JoinDate;
            _projectMemberRepository.Update(entity);
            await _projectMemberRepository.SaveAsync();

            return(entity.ToModel());
        }
Пример #5
0
 public void Update(RTC_ProjectMember member)
 {
     projectMemberRepository.Update(member);
 }