public async Task <LabelDeleteResponse> DeleteLabel(LabelDeleteRequest request) { var response = new LabelDeleteResponse(); var label = await _labelRepository.Select(x => x.Uid == request.LabelUid); if (label.IsNotExist()) { response.SetInvalid(); response.ErrorMessages.Add("label_not_found"); return(response); } var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId); if (label.OrganizationId != currentUser.OrganizationId) { response.SetInvalid(); return(response); } if (await _organizationRepository.Any(x => x.Id == label.OrganizationId && !x.IsActive)) { response.SetInvalid(); response.ErrorMessages.Add("organization_not_found"); return(response); } if (await _projectRepository.Any(x => x.Id == label.ProjectId && !x.IsActive)) { response.SetInvalid(); response.ErrorMessages.Add("project_not_active"); return(response); } if (await _labelTranslationRepository.Any(x => x.LabelId == label.Id)) { response.SetInvalid(); response.ErrorMessages.Add("has_children"); return(response); } var uowResult = await _labelUnitOfWork.DoDeleteWork(request.CurrentUserId, label); if (uowResult) { response.Status = ResponseStatus.Success; return(response); } response.SetFailed(); return(response); }
public async Task <LabelDeleteResponse> DeleteLabel(LabelDeleteRequest request) { var response = new LabelDeleteResponse(); var label = await _labelRepository.Select(x => x.Uid == request.LabelUid); if (label.IsNotExist()) { response.SetInvalidBecauseEntityNotFound(); return(response); } var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId); if (label.OrganizationId != currentUser.OrganizationId) { response.SetInvalid(); return(response); } if (await _organizationRepository.Any(x => x.Id == label.OrganizationId && !x.IsActive)) { response.SetInvalidBecauseParentNotActive(); return(response); } if (await _projectRepository.Any(x => x.Id == label.ProjectId && !x.IsActive)) { response.SetInvalidBecauseParentNotActive(); return(response); } if (await _labelTranslationRepository.Any(x => x.LabelId == label.Id)) { response.SetInvalidForDeleteBecauseHasChildren(); return(response); } var uowResult = await _labelUnitOfWork.DoDeleteWork(request.CurrentUserId, label); if (uowResult) { response.Status = ResponseStatus.Success; return(response); } response.SetFailed(); return(response); }