public ActionResult Approve(string id) { id = id.NullSafe(); JsonViewData viewData = Validate <JsonViewData>( new Validation(() => string.IsNullOrEmpty(id), "Identyfikator artyku³u nie mo¿e byæ pusty."), new Validation(() => id.ToGuid().IsEmpty(), "Niepoprawny identyfikator artyku³u."), new Validation(() => !IsCurrentUserAuthenticated, "Nie jesteœ zalogowany."), new Validation(() => !CurrentUser.CanModerate(), "Nie masz praw do wo³ania tej metody.") ); if (viewData == null) { try { using (IUnitOfWork unitOfWork = UnitOfWork.Get()) { IStory story = _storyRepository.FindById(id.ToGuid()); if (story == null) { viewData = new JsonViewData { errorMessage = "Podany artyku³ nie istnieje." }; } else { if (story.IsApproved()) { viewData = new JsonViewData { errorMessage = "Podany artyku³ ju¿ zosta³ zatwierdzony jako spam." }; } else { _storyService.Approve(story, string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName })), CurrentUser); unitOfWork.Commit(); viewData = new JsonViewData { isSuccessful = true }; } } } } catch (Exception e) { Log.Exception(e); viewData = new JsonViewData { errorMessage = FormatStrings.UnknownError.FormatWith("aprobowania artyku³u") }; } } return(Json(viewData)); }
public ActionResult Approve(string id) { id = id.NullSafe(); JsonViewData viewData = Validate <JsonViewData>( new Validation(() => string.IsNullOrEmpty(id), "Story identifier cannot be blank."), new Validation(() => id.ToGuid().IsEmpty(), "Invalid story identifier."), new Validation(() => !IsCurrentUserAuthenticated, "You are currently not authenticated."), new Validation(() => !CurrentUser.CanModerate(), "You do not have the privilege to call this method.") ); if (viewData == null) { try { IStory story = _storyRepository.FindById(id.ToGuid()); if (story == null) { viewData = new JsonViewData { errorMessage = "Specified story does not exist." }; } else { if (story.IsApproved()) { viewData = new JsonViewData { errorMessage = "Specified story has been already approved." }; } else { _storyService.Approve(story, string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName })), CurrentUser); viewData = new JsonViewData { isSuccessful = true }; } } } catch (Exception e) { Log.Exception(e); viewData = new JsonViewData { errorMessage = FormatStrings.UnknownError.FormatWith("approving story") }; } } return(Json(viewData)); }