public async Task <ProjectDeleteResponse> DeleteProject(ProjectDeleteRequest request) { var response = new ProjectDeleteResponse(); 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.SetInvalid(); response.ErrorMessages.Add("project_not_found"); return(response); } if (project.OrganizationId != currentUser.OrganizationId) { response.SetFailed(); return(response); } if (await _organizationRepository.Any(x => x.Id == project.OrganizationId && !x.IsActive)) { response.SetInvalid(); return(response); } if (await _labelRepository.Any(x => x.ProjectId == project.Id)) { response.SetInvalid(); response.ErrorMessages.Add("has_children"); return(response); } var result = await _projectRepository.Delete(request.CurrentUserId, project.Id); if (result) { response.Status = ResponseStatus.Success; return(response); } var uowResult = await _projectUnitOfWork.DoDeleteWork(request.CurrentUserId, project); if (uowResult) { response.Status = ResponseStatus.Success; return(response); } response.SetFailed(); return(response); }
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); }
private bool LabelExists(int id) { //return _context.Labels.Any(e => e.LabelId == id); // Original scaffold call using context directly return(_repository.Any(id)); }