예제 #1
0
        public async Task <dynamic> PutAsync(Guid id, [FromBody] ProjectEditRequest request, CancellationToken cancellationToken)
        {
            request.Id = id;
            var result = await _mediator.Send(request, cancellationToken);

            return(new HRAssistActionResult(result));
        }
예제 #2
0
        public static ProjectEditRequest GetProjectEditRequest(Project project)
        {
            var request = new ProjectEditRequest(CurrentUserId, project.OrganizationUid, project.Uid,
                                                 project.Name, project.Url, project.Description);

            return(request);
        }
예제 #3
0
        public static ProjectEditRequest GetProjectEditRequest()
        {
            var request = new ProjectEditRequest(CurrentUserId, OrganizationOneUid, UidOne,
                                                 StringOne, HttpUrl, StringOne);

            return(request);
        }
예제 #4
0
        public Project CreateEntityFromRequest(ProjectEditRequest request, Project entity)
        {
            entity.Name = request.ProjectName;

            entity.Description = request.Description;
            entity.Url         = request.Url;

            return(entity);
        }
예제 #5
0
        public async Task <ProjectEditResponse> EditProject(ProjectEditRequest request)
        {
            var response = new ProjectEditResponse();

            var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId);

            if (!currentUser.IsAdmin)
            {
                response.SetInvalid();
                return(response);
            }

            if (await _organizationRepository.Any(x => x.Id == currentUser.OrganizationId && !x.IsActive))
            {
                response.SetInvalid();
                response.ErrorMessages.Add("organization_not_active");
                return(response);
            }

            var project = await _projectRepository.Select(x => x.Uid == request.ProjectUid);

            if (project.IsNotExist())
            {
                response.SetInvalid();
                response.ErrorMessages.Add("project_not_found");
                return(response);
            }

            if (project.OrganizationId != currentUser.OrganizationId)
            {
                response.SetFailed();
                return(response);
            }

            if (await _projectRepository.Any(x => x.Name == request.ProjectName &&
                                             x.OrganizationId == project.OrganizationId &&
                                             x.Id != project.Id))
            {
                response.ErrorMessages.Add("project_name_must_be_unique");
                response.Status = ResponseStatus.Failed;
                return(response);
            }

            var updatedEntity = _projectFactory.CreateEntityFromRequest(request, project);
            var result        = await _projectRepository.Update(request.CurrentUserId, updatedEntity);

            if (result)
            {
                response.Item   = _projectFactory.CreateDtoFromEntity(updatedEntity);
                response.Status = ResponseStatus.Success;
                return(response);
            }

            response.SetFailed();
            return(response);
        }
예제 #6
0
        public async Task <IActionResult> Edit(ProjectEditModel model)
        {
            if (model.IsNotValid())
            {
                model.SetInputModelValues();
                return(View(model));
            }

            var request = new ProjectEditRequest(CurrentUser.Id, model.OrganizationUid, model.ProjectUid,
                                                 model.Name, model.Url, model.Description);
            var response = await _projectService.EditProject(request);

            if (response.Status.IsNotSuccess)
            {
                model.MapMessages(response);
                return(View(model));
            }

            CurrentUser.IsActionSucceed = true;
            return(Redirect($"/Project/Detail/{ model.ProjectUid}"));
        }