public async Task <IActionResult> Restore(Guid id, int revision) { var model = new CommonResult { IsOk = false }; var languageUid = id; if (languageUid.IsEmptyGuid()) { return(Json(model)); } if (revision < 1) { return(Json(model)); } var request = new LanguageRestoreRequest(CurrentUser.Id, languageUid, revision); var response = await _languageService.RestoreLanguage(request); if (response.Status.IsNotSuccess) { model.Messages = response.ErrorMessages; return(Json(model)); } model.IsOk = true; CurrentUser.IsActionSucceed = true; return(Json(model)); }
public async Task <LanguageRestoreResponse> RestoreLanguage(LanguageRestoreRequest request) { var response = new LanguageRestoreResponse(); var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId); var language = await _languageRepository.Select(x => x.Uid == request.LanguageUid); if (language.IsNotExist()) { response.SetInvalidBecauseEntityNotFound(); response.InfoMessages.Add("language_not_found"); return(response); } var revisions = await _languageRepository.SelectRevisions(language.Id); if (revisions.All(x => x.Revision != request.Revision)) { response.SetInvalidBecauseEntityNotFound(); response.InfoMessages.Add("revision_not_found"); return(response); } var result = await _languageRepository.RestoreRevision(request.CurrentUserId, language.Id, request.Revision); if (result) { response.Status = ResponseStatus.Success; return(response); } response.SetFailed(); return(response); }
public static LanguageRestoreRequest GetLanguageRestoreRequest() { var request = new LanguageRestoreRequest(CurrentUserId, UidOne, One); return(request); }