Esempio n. 1
0
        public async Task <AdminInviteValidateResponse> ValidateSuperAdminUserInvitation(AdminInviteValidateRequest request)
        {
            var response = new AdminInviteValidateResponse();

            var user = await _userRepository.Select(x => x.InvitationToken == request.Token && x.Email == request.Email);

            if (user.IsNotExist())
            {
                response.SetInvalidBecauseNotFound("user");
                return(response);
            }

            if (await _organizationRepository.Any(x => x.Id == user.OrganizationId && !x.IsActive))
            {
                response.SetInvalidBecauseNotFound("organization");
                return(response);
            }

            if (user.InvitedAt.HasValue &&
                user.InvitedAt.Value.AddDays(2) > DateTime.UtcNow)
            {
                response.Item.FirstName = user.FirstName;
                response.Item.LastName  = user.LastName;
                response.Item.Email     = user.Email;
                response.Status         = ResponseStatus.Success;
                return(response);
            }

            response.SetFailed();
            return(response);
        }
        public async Task <OrganizationEditResponse> EditOrganization(OrganizationEditRequest request)
        {
            var response = new OrganizationEditResponse();

            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_found");
                return(response);
            }

            var entity = _cacheManager.GetCachedOrganization(currentUser.OrganizationUid);

            if (entity.Id != currentUser.OrganizationId)
            {
                response.SetInvalid();
                return(response);
            }

            if (await _organizationRepository.Any(x => x.Name == request.Name && x.Id != currentUser.OrganizationId))
            {
                response.ErrorMessages.Add("organization_name_already_exist");
                response.Status = ResponseStatus.Invalid;
            }

            var updatedEntity = _organizationFactory.CreateEntityFromRequest(request, entity);
            var result        = await _organizationRepository.Update(request.CurrentUserId, updatedEntity);

            if (result)
            {
                _cacheManager.UpsertOrganizationCache(updatedEntity, _organizationFactory.MapCurrentOrganization(updatedEntity));

                response.Item   = _organizationFactory.CreateDtoFromEntity(updatedEntity);
                response.Status = ResponseStatus.Success;
                return(response);
            }

            response.SetFailed();
            return(response);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public async Task <IntegrationCreateResponse> CreateIntegration(IntegrationCreateRequest request)
        {
            var response = new IntegrationCreateResponse();

            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.SetInvalidBecauseNotActive("organization");
                return(response);
            }

            if (await _integrationRepository.Any(x => x.Name == request.Name && x.OrganizationId == currentUser.OrganizationId))
            {
                response.SetFailedBecauseNameMustBeUnique("integration");
                return(response);
            }

            var entity = _integrationFactory.CreateEntityFromRequest(request, currentUser.Organization);
            await _integrationRepository.Insert(request.CurrentUserId, entity);

            response.Item   = _integrationFactory.CreateDtoFromEntity(entity);
            response.Status = ResponseStatus.Success;
            return(response);
        }
Esempio n. 5
0
        public async Task <LabelCreateResponse> CreateLabel(LabelCreateRequest request)
        {
            var response = new LabelCreateResponse();

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

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

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

            if (project.IsNotExist())
            {
                response.SetInvalidBecauseNotFound("project");
                return(response);
            }

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

            if (await _organizationRepository.Any(x => x.Id == project.OrganizationId && !x.IsActive))
            {
                response.SetInvalid();
                return(response);
            }

            if (await _labelRepository.Any(x => x.Key == request.LabelKey && x.ProjectId == project.Id))
            {
                response.ErrorMessages.Add("label_key_must_be_unique");
                response.Status = ResponseStatus.Failed;
                return(response);
            }

            var label     = _labelFactory.CreateEntityFromRequest(request, project);
            var uowResult = await _labelUnitOfWork.DoCreateWork(request.CurrentUserId, label);

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

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