public async Task <IActionResult> LabelTranslationCreate(LabelTranslationCreateModel model) { if (model.IsNotValid()) { model.SetInputModelValues(); return(View(model)); } var request = new LabelTranslationCreateRequest(CurrentUser.Id, model.OrganizationUid, model.LabelUid, model.LanguageUid, model.LabelTranslation); var response = await _labelService.CreateTranslation(request); if (response.Status.IsNotSuccess) { model.MapMessages(response); model.SetInputModelValues(); return(View(model)); } CurrentUser.IsActionSucceed = true; return(Redirect($"/Label/Detail/{response.Item.LabelUid}")); }
public async Task <LabelTranslationCreateResponse> CreateTranslation(LabelTranslationCreateRequest request) { var response = new LabelTranslationCreateResponse(); var label = await _labelRepository.Select(x => x.Uid == request.LabelUid); if (label.IsNotExist()) { response.SetInvalid(); response.ErrorMessages.Add("label_not_found"); return(response); } if (!label.IsActive) { response.SetInvalid(); response.ErrorMessages.Add("label_not_active"); 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_active"); return(response); } if (await _projectRepository.Any(x => x.Id == label.ProjectId && !x.IsActive)) { response.SetInvalid(); response.ErrorMessages.Add("project_not_active"); return(response); } var language = await _languageRepository.Select(x => x.Uid == request.LanguageUid); if (language.IsNotExist()) { response.SetInvalid(); response.ErrorMessages.Add("language_not_found"); return(response); } if (await _labelTranslationRepository.Any(x => x.Translation == request.LabelTranslation && x.LanguageId == language.Id && x.LabelId == label.Id)) { response.ErrorMessages.Add("label_translation_must_be_unique"); response.Status = ResponseStatus.Failed; return(response); } var labelTranslation = _labelTranslationFactory.CreateEntity(request.LabelTranslation, label, language); var uowResult = await _labelUnitOfWork.DoCreateTranslationWork(request.CurrentUserId, labelTranslation); if (uowResult) { response.Item = _labelTranslationFactory.CreateDtoFromEntity(labelTranslation, language); response.Status = ResponseStatus.Success; return(response); } response.SetFailed(); return(response); }
public static LabelTranslationCreateRequest GetLabelTranslationCreateRequest() { var request = new LabelTranslationCreateRequest(CurrentUserId, UidOne, UidOne, UidOne, StringOne); return(request); }