public async Task <IActionResult> RestoreLabelTranslation(Guid id, int revision) { var model = new CommonResult { IsOk = false }; var labelTranslationUid = id; if (labelTranslationUid.IsEmptyGuid()) { return(Json(model)); } if (revision < 1) { return(Json(model)); } var request = new LabelTranslationRestoreRequest(CurrentUser.Id, labelTranslationUid, revision); var response = await _labelService.RestoreLabelTranslation(request); if (response.Status.IsNotSuccess) { model.Messages = response.ErrorMessages; return(Json(model)); } model.IsOk = true; CurrentUser.IsActionSucceed = true; return(Json(model)); }
public async Task <LabelTranslationRestoreResponse> RestoreLabelTranslation(LabelTranslationRestoreRequest request) { var response = new LabelTranslationRestoreResponse(); var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId); if (await _organizationRepository.Any(x => x.Id == currentUser.OrganizationId && !x.IsActive)) { response.SetInvalid(); return(response); } var labelTranslation = await _labelTranslationRepository.Select(x => x.Uid == request.LabelTranslationUid); if (labelTranslation.IsNotExist()) { response.SetInvalid(); response.InfoMessages.Add("label_translation_not_found"); return(response); } var revisions = await _labelTranslationRepository.SelectRevisions(labelTranslation.Id); if (revisions.All(x => x.Revision != request.Revision)) { response.SetInvalid(); response.InfoMessages.Add("revision_not_found"); return(response); } var result = await _labelTranslationRepository.RestoreRevision(request.CurrentUserId, labelTranslation.Id, request.Revision); if (result) { response.Status = ResponseStatus.Success; return(response); } response.SetFailed(); return(response); }
public static LabelTranslationRestoreRequest GetLabelTranslationRestoreRequest() { var request = new LabelTranslationRestoreRequest(CurrentUserId, UidOne, One); return(request); }