public ActionResult MarkAsSpam(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.CanMarkAsSpam(CurrentUser)) { viewData = story.HasMarkedAsSpam(CurrentUser) ? new JsonViewData { errorMessage = "Ju¿ zaznaczy³eœ ten artyku³ jako spam." } : new JsonViewData { errorMessage = "Nie masz uprawnieñ do zaznaczania tego artyku³u jako spam." }; } else { _storyService.MarkAsSpam(story, string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName })), CurrentUser, CurrentUserIPAddress); unitOfWork.Commit(); viewData = new JsonViewData { isSuccessful = true }; } } } } catch (Exception e) { Log.Exception(e); viewData = new JsonViewData { errorMessage = FormatStrings.UnknownError.FormatWith("oznaczania artyku³u jako spam") }; } } return(Json(viewData)); }
public ActionResult MarkAsSpam(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.CanMarkAsSpam(CurrentUser)) { viewData = story.HasMarkedAsSpam(CurrentUser) ? new JsonViewData { errorMessage = "You have already marked this story as spam." } : new JsonViewData { errorMessage = "You are not allowed to mark this story as spam." }; } else { _storyService.MarkAsSpam(story, string.Concat(Settings.RootUrl, Url.RouteUrl("Detail", new { name = story.UniqueName })), CurrentUser, CurrentUserIPAddress); viewData = new JsonViewData { isSuccessful = true }; } } } catch (Exception e) { Log.Exception(e); viewData = new JsonViewData { errorMessage = FormatStrings.UnknownError.FormatWith("marking story as spam") }; } } return(Json(viewData)); }