public ActionResult Demote(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.") ); 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.CanDemote(CurrentUser)) { viewData = new JsonViewData { errorMessage = "Nie mo¿esz degradowaæ tego artyku³u." }; } else { _storyService.Demote(story, CurrentUser); unitOfWork.Commit(); viewData = new JsonVoteViewData { isSuccessful = true, votes = story.VoteCount, text = GetText(story.VoteCount) }; } } } } catch (Exception e) { Log.Exception(e); viewData = new JsonViewData { errorMessage = FormatStrings.UnknownError.FormatWith("degradowania artyku³u") }; } } return(Json(viewData)); }
public ActionResult Demote(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.") ); 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.CanDemote(CurrentUser)) { viewData = new JsonViewData { errorMessage = "You are not allowed to demote this story." }; } else { _storyService.Demote(story, CurrentUser); viewData = new JsonVoteViewData { isSuccessful = true, votes = story.VoteCount }; } } } catch (Exception e) { Log.Exception(e); viewData = new JsonViewData { errorMessage = FormatStrings.UnknownError.FormatWith("demoting story") }; } } return(Json(viewData)); }