Example #1
0
        public async Task <ProjectCreateResponse> CreateProject(ProjectCreateRequest request)
        {
            var response = new ProjectCreateResponse();

            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.SetInvalidBecauseParentNotActive();
                return(response);
            }

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

            var entity    = _projectFactory.CreateEntityFromRequest(request, currentUser.Organization);
            var uowResult = await _projectUnitOfWork.DoCreateWork(request.CurrentUserId, entity);

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

            response.SetFailed();
            return(response);
        }