public async Task <IActionResult> DisplayOne(int id) { var record = DbContext.Messages.Find(id); if (record is null) { throw new HttpNotFoundError(); } var topicId = id; if (record.ParentId > 0) { topicId = record.ParentId; } await LoadTopicBoards(topicId); var messageIds = new List <int> { id }; var messages = await MessageRepository.GetMessages(messageIds); var viewModel = new PageModels.TopicDisplayPartialPage { Latest = DateTime.Now.Ticks, Messages = messages }; return(await ForumViewResult.ViewResult(this, "DisplayPartial", viewModel)); }
public async Task <IActionResult> Details(string id) { var userRecord = id is null ? UserContext.ApplicationUser : await UserManager.FindByIdAsync(id); if (userRecord is null) { userRecord = UserContext.ApplicationUser; } AccountRepository.CanEdit(userRecord.Id); var viewModel = new ViewModels.Account.DetailsPage { AvatarPath = userRecord.AvatarPath, Id = userRecord.Id, DisplayName = userRecord.DisplayName, NewEmail = userRecord.Email, EmailConfirmed = userRecord.EmailConfirmed, BirthdayDays = DayPickList(userRecord.Birthday.Day), BirthdayMonths = MonthPickList(userRecord.Birthday.Month), BirthdayYears = YearPickList(userRecord.Birthday.Year), BirthdayDay = userRecord.Birthday.Day.ToString(), BirthdayMonth = userRecord.Birthday.Month.ToString(), BirthdayYear = userRecord.Birthday.Year.ToString(), Settings = SettingsRepository.GetUserSettingsList(userRecord.Id) }; ModelState.Clear(); return(ForumViewResult.ViewResult(this, viewModel)); }
public IActionResult Index() { var viewModel = new ViewModels.Account.IndexPage(); foreach (var user in AccountRepository) { if (user.DisplayName == "Deleted Account") { continue; } var indexItem = new ViewModels.Account.IndexItem { Id = user.Id, DisplayName = user.DisplayName, Email = user.Email, Registered = user.Registered.ToPassedTimeString(), LastOnline = user.LastOnline.ToPassedTimeString(), CanManage = UserContext.IsAdmin || user.Id == UserContext.ApplicationUser.Id }; viewModel.IndexItems.Add(indexItem); } return(ForumViewResult.ViewResult(this, viewModel)); }
public IActionResult Index(int id = 0, int unread = 0) { var boardRoles = RoleRepository.BoardRoles.Where(r => r.BoardId == id).Select(r => r.RoleId).ToList(); if (!UserContext.IsAdmin && boardRoles.Any() && !boardRoles.Intersect(UserContext.Roles).Any()) { throw new HttpForbiddenError(); } var sidebar = new ViewModels.Sidebar { Birthdays = AccountRepository.GetBirthdaysList().ToArray(), OnlineUsers = AccountRepository.GetOnlineList(), Notifications = NotificationRepository.Index() }; var page = 1; var topicPreviews = TopicRepository.GetPreviews(id, page, unread); var boardRecord = id == 0 ? null : BoardRepository.FirstOrDefault(record => record.Id == id); var viewModel = new PageModels.TopicIndexPage { BoardId = id, BoardName = boardRecord?.Name ?? "All Topics", Page = page, Topics = topicPreviews, UnreadFilter = unread, Sidebar = sidebar }; return(ForumViewResult.ViewResult(this, viewModel)); }
public IActionResult MergeMore(int id, int page = 0) { var record = DbContext.Messages.FirstOrDefault(item => item.Id == id); if (record is null) { throw new HttpNotFoundError(); } var topicPreviews = TopicRepository.GetPreviews(0, page, 0); foreach (var topicPreview in topicPreviews.ToList()) { if (topicPreview.Id == id) { topicPreviews.Remove(topicPreview); } else { topicPreview.SourceId = id; } } var viewModel = new PageModels.TopicIndexMorePage { More = topicPreviews.Any(), Page = page, Topics = topicPreviews }; return(ForumViewResult.ViewResult(this, viewModel)); }
public IActionResult Merge(int id) { var record = DbContext.Messages.FirstOrDefault(item => item.Id == id); if (record is null) { throw new HttpNotFoundError(); } var topicPreviews = TopicRepository.GetPreviews(0, 1, 0); foreach (var topicPreview in topicPreviews.ToList()) { if (topicPreview.Id == id) { topicPreviews.Remove(topicPreview); } else { topicPreview.SourceId = id; } } var viewModel = new PageModels.TopicIndexPage { SourceId = id, BoardName = "Pick a Destination Topic", BoardId = 0, Page = 1, Topics = topicPreviews, }; return(ForumViewResult.ViewResult(this, viewModel)); }
public async Task <IActionResult> DisplayPartial(int id, long latest) { var latestTime = new DateTime(latest); var record = DbContext.Messages.Find(id); if (record is null) { throw new HttpNotFoundError(); } var topicId = id; if (record.ParentId > 0) { topicId = record.ParentId; } await LoadTopicBoards(topicId); var messageIds = MessageRepository.GetMessageIds(topicId, latestTime); var messages = await MessageRepository.GetMessages(messageIds); var latestMessageTime = messages.Max(r => r.RecordTime); TopicRepository.MarkRead(topicId, latestMessageTime, messageIds); var viewModel = new PageModels.TopicDisplayPartialPage { Latest = DateTime.Now.Ticks, Messages = messages }; return(await ForumViewResult.ViewResult(this, "DisplayPartial", viewModel)); }
public async Task <IActionResult> Index(int id = 0, int pageId = 1, int unread = 0) { var messageIds = await TopicRepository.GetIndexIds(id, pageId, unread); var morePages = true; if (messageIds.Count < UserContext.ApplicationUser.TopicsPerPage) { morePages = false; } var topicPreviews = await TopicRepository.GetPreviews(messageIds); var boardRecord = id == 0 ? null : (await BoardRepository.Records()).FirstOrDefault(record => record.Id == id); var viewModel = new PageModels.TopicIndexPage { BoardId = id, BoardName = boardRecord?.Name ?? "All Topics", CurrentPage = pageId, Topics = topicPreviews, UnreadFilter = unread, MorePages = morePages }; return(await ForumViewResult.ViewResult(this, viewModel)); }
public async Task <IActionResult> Details(string id = "") { var userRecord = string.IsNullOrEmpty(id) ? UserContext.ApplicationUser : await UserManager.FindByIdAsync(id); if (userRecord is null) { userRecord = UserContext.ApplicationUser; } AccountRepository.CanEdit(userRecord.Id); var viewModel = new ViewModels.Account.DetailsPage { AvatarPath = userRecord.AvatarPath, Id = userRecord.Id, DisplayName = userRecord.DisplayName, NewEmail = userRecord.Email, EmailConfirmed = userRecord.EmailConfirmed, BirthdayDays = DayPickList(userRecord.Birthday.Day), BirthdayMonths = MonthPickList(userRecord.Birthday.Month), BirthdayDay = userRecord.Birthday.Day.ToString(), BirthdayMonth = userRecord.Birthday.Month.ToString(), FrontPage = userRecord.FrontPage, FrontPageOptions = FrontPagePickList(userRecord.FrontPage), MessagesPerPage = userRecord.MessagesPerPage, PopularityLimit = userRecord.PopularityLimit, Poseys = userRecord.Poseys, ShowFavicons = userRecord.ShowFavicons, TopicsPerPage = userRecord.TopicsPerPage, ShowBirthday = userRecord.ShowBirthday }; ModelState.Clear(); return(await ForumViewResult.ViewResult(this, viewModel)); }
public async Task <IActionResult> RecountReplies(InputModels.Continue input) { if (string.IsNullOrEmpty(input.Stage)) { var totalSteps = await MessageRepository.RecountReplies(); input = new InputModels.Continue { Stage = nameof(MessageRepository.RecountReplies), CurrentStep = -1, TotalSteps = totalSteps }; } else { await MessageRepository.RecountRepliesContinue(input); } var viewModel = new ViewModels.Delay { ActionName = "Recounting Replies", CurrentPage = input.CurrentStep, TotalPages = input.TotalSteps, NextAction = UrlHelper.Action(nameof(Messages.Admin), nameof(Messages)) }; if (input.CurrentStep < input.TotalSteps) { input.CurrentStep++; viewModel.NextAction = UrlHelper.Action(nameof(Messages.RecountReplies), nameof(Messages), input); } return(await ForumViewResult.ViewResult(this, "Delay", viewModel)); }
public async Task <IActionResult> Delete(string userId = "") { if (string.IsNullOrEmpty(userId)) { throw new HttpBadRequestError(); } var deletedAccount = (await AccountRepository.Records()).FirstOrDefault(item => item.DisplayName == "Deleted Account"); if (deletedAccount is null) { deletedAccount = new DataModels.ApplicationUser { DisplayName = "Deleted Account", UserName = Guid.NewGuid().ToString(), Email = Guid.NewGuid().ToString(), AvatarPath = string.Empty, Birthday = new DateTime(2000, 1, 1), Registered = new DateTime(2000, 1, 1), }; DbContext.Users.Add(deletedAccount); DbContext.SaveChanges(); } return(await ForumViewResult.ViewResult(this, "Delete", userId)); }
public async Task <IActionResult> Merge(string userId = "") { if (string.IsNullOrEmpty(userId)) { throw new HttpBadRequestError(); } var viewModel = new ViewModels.Account.MergePage { SourceId = userId }; foreach (var user in (await AccountRepository.Records()).Where(item => item.Id != userId && item.DisplayName != "Deleted Account")) { var indexItem = new ViewModels.Account.IndexItem { Id = user.Id, DisplayName = user.DisplayName, Email = user.Email, Registered = user.Registered.ToPassedTimeString(), LastOnline = user.LastOnline.ToPassedTimeString(), CanManage = UserContext.IsAdmin || user.Id == UserContext.ApplicationUser.Id }; viewModel.IndexItems.Add(indexItem); } return(await ForumViewResult.ViewResult(this, viewModel)); }
public async Task <IActionResult> Login(InputModels.LoginInput input) { if (ModelState.IsValid) { var serviceResponse = await AccountRepository.Login(input); return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback)); } return(await FailureCallback()); async Task <IActionResult> FailureCallback() { if (AccountRepository.IsAuthenticated) { return(RedirectToAction(nameof(Home.FrontPage), nameof(Home))); } await AccountRepository.SignOut(); var viewModel = new ViewModels.Account.LoginPage { Email = input.Email, RememberMe = input.RememberMe }; return(ForumViewResult.ViewResult(this, viewModel)); } }
public async Task <IActionResult> Details(InputModels.UpdateAccountInput input) { if (ModelState.IsValid) { var serviceResponse = await AccountRepository.UpdateAccount(input); return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback)); } return(await FailureCallback()); async Task <IActionResult> FailureCallback() { var userRecord = AccountRepository.First(item => item.Id == input.Id); AccountRepository.CanEdit(userRecord.Id); var viewModel = new ViewModels.Account.DetailsPage { DisplayName = input.DisplayName, NewEmail = input.NewEmail, AvatarPath = userRecord.AvatarPath, Id = userRecord.Id, EmailConfirmed = userRecord.EmailConfirmed, BirthdayDays = DayPickList(input.BirthdayDay), BirthdayMonths = MonthPickList(input.BirthdayMonth), BirthdayYears = YearPickList(input.BirthdayYear), BirthdayDay = input.BirthdayDay.ToString(), BirthdayMonth = input.BirthdayMonth.ToString(), BirthdayYear = input.BirthdayYear.ToString(), Settings = SettingsRepository.GetUserSettingsList(userRecord.Id) }; return(await Task.Run(() => { return ForumViewResult.ViewResult(this, viewModel); })); } }
public async Task <IActionResult> Register(InputModels.RegisterInput input) { if (ModelState.IsValid) { var serviceResponse = await AccountRepository.Register(input); return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback)); } return(await FailureCallback()); async Task <IActionResult> FailureCallback() { await AccountRepository.SignOut(); var viewModel = new ViewModels.Account.RegisterPage { BirthdayDays = DayPickList(), BirthdayDay = input.BirthdayDay.ToString(), BirthdayMonths = MonthPickList(), BirthdayMonth = input.BirthdayMonth.ToString(), BirthdayYears = YearPickList(), BirthdayYear = input.BirthdayYear.ToString(), DisplayName = input.DisplayName, Email = input.Email, ConfirmEmail = input.ConfirmEmail, Password = input.Password, ConfirmPassword = input.ConfirmPassword, }; return(ForumViewResult.ViewResult(this, viewModel)); } }
public IActionResult RebuildParticipants(InputModels.Continue input) { if (string.IsNullOrEmpty(input.Stage)) { var totalSteps = MessageRepository.RebuildParticipants(); input = new InputModels.Continue { Stage = nameof(MessageRepository.RebuildParticipants), CurrentStep = -1, TotalSteps = totalSteps }; } else { MessageRepository.RebuildParticipantsContinue(input); } var viewModel = new ViewModels.Delay { ActionName = "Rebuilding participants", CurrentPage = input.CurrentStep, TotalPages = input.TotalSteps, NextAction = UrlHelper.Action(nameof(Messages.Admin), nameof(Messages)) }; if (input.CurrentStep < input.TotalSteps) { input.CurrentStep++; viewModel.NextAction = UrlHelper.Action(nameof(Messages.RebuildParticipants), nameof(Messages), input); } return(ForumViewResult.ViewResult(this, "Delay", viewModel)); }
public async Task <IActionResult> ReprocessMessages(InputModels.Continue input) { if (string.IsNullOrEmpty(input.Stage)) { var totalSteps = MessageRepository.ReprocessMessages(); input = new InputModels.Continue { Stage = nameof(MessageRepository.ReprocessMessages), CurrentStep = -1, TotalSteps = totalSteps }; } else { await MessageRepository.ReprocessMessagesContinue(input); } var viewModel = new ViewModels.Delay { ActionName = "Reprocessing Messages", ActionNote = "Processing message text, loading external sites, replacing smiley codes.", CurrentPage = input.CurrentStep, TotalPages = input.TotalSteps, NextAction = UrlHelper.Action(nameof(Messages.Admin), nameof(Messages)) }; if (input.CurrentStep < input.TotalSteps) { input.CurrentStep++; viewModel.NextAction = UrlHelper.Action(nameof(Messages.ReprocessMessages), nameof(Messages), input); } return(ForumViewResult.ViewResult(this, "Delay", viewModel)); }
public async Task <IActionResult> ForgotPassword() { await AccountRepository.SignOut(); var viewModel = new ViewModels.Account.ForgotPasswordPage(); return(ForumViewResult.ViewResult(this, viewModel)); }
public async Task <IActionResult> Error() { var viewModel = new ViewModels.Error { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }; return(await ForumViewResult.ViewResult(this, viewModel)); }
public async Task <IActionResult> Test() { var viewModel = new List <string> { UrlHelper.Action(nameof(TestStage1)), UrlHelper.Action(nameof(TestStage2)), UrlHelper.Action(nameof(TestStage3)), }; return(await ForumViewResult.ViewResult(this, "Process", viewModel)); }
public async Task <IActionResult> Bookmarks() { var messageIds = (await BookmarkRepository.Records()).Select(r => r.MessageId).ToList(); var topicPreviews = await TopicRepository.GetPreviews(messageIds); var viewModel = new PageModels.TopicBookmarksPage { Topics = topicPreviews }; return(await ForumViewResult.ViewResult(this, viewModel)); }
public async Task <IActionResult> Register() { await AccountRepository.SignOut(); var viewModel = new ViewModels.Account.RegisterPage { BirthdayDays = DayPickList(), BirthdayMonths = MonthPickList(), BirthdayYears = YearPickList() }; return(ForumViewResult.ViewResult(this, viewModel)); }
public async Task <IActionResult> ResetPassword(string code) { code.ThrowIfNull(nameof(code)); await AccountRepository.SignOut(); var viewModel = new ViewModels.Account.ResetPasswordPage { Code = code }; return(ForumViewResult.ViewResult(this, viewModel)); }
public async Task <IActionResult> ConfirmEmail(InputModels.ConfirmEmailInput input) { if (ModelState.IsValid) { var serviceResponse = await AccountRepository.ConfirmEmail(input); return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback)); } return(await FailureCallback()); async Task <IActionResult> FailureCallback() => await ForumViewResult.ViewResult(this); }
public async Task <IActionResult> LoginClassic() { if (UserContext.IsAuthenticated) { return(Redirect("/")); } await AccountRepository.SignOut(); var viewModel = new ViewModels.Account.LoginPage(); return(await ForumViewResult.ViewResult(this, viewModel)); }
public async Task <IActionResult> Login() { if (AccountRepository.IsAuthenticated) { return(RedirectToAction(nameof(Home.FrontPage), nameof(Home))); } await AccountRepository.SignOut(); var viewModel = new ViewModels.Account.LoginPage(); return(ForumViewResult.ViewResult(this, viewModel)); }
public async Task <IActionResult> ResetPassword(string code = "") { if (string.IsNullOrEmpty(code)) { throw new HttpBadRequestError(); } await AccountRepository.SignOut(); var viewModel = new ViewModels.Account.ResetPasswordPage { Code = code }; return(await ForumViewResult.ViewResult(this, viewModel)); }
public async Task <IActionResult> Display(int id, int pageId = 1, int target = -1) { ViewData["Smileys"] = await SmileyRepository.GetSelectorList(); var viewModel = await GetDisplayPageModel(id, pageId, target); if (string.IsNullOrEmpty(viewModel.RedirectPath)) { return(await ForumViewResult.ViewResult(this, viewModel)); } else { return(Redirect(viewModel.RedirectPath)); } }
public async Task <IActionResult> Process(InputModels.Continue input) { CheckContext(); var note = string.Empty; switch (input.CurrentStep) { case 1: note = "Roles have been setup."; await SetupService.SetupRoles(); break; case 2: note = "Admins have been added."; await SetupService.SetupAdmins(); break; case 3: note = "The first category has been added."; SetupService.SetupCategories(); break; case 4: note = "The first board has been added."; SetupService.SetupBoards(); break; } input.CurrentStep++; var viewModel = new ViewModels.Delay { ActionName = "Processing", ActionNote = note, CurrentPage = input.CurrentStep, TotalPages = input.TotalSteps, NextAction = UrlHelper.Action(nameof(Setup.Process), nameof(Setup), input) }; if (input.CurrentStep > input.TotalSteps) { viewModel.NextAction = "/"; } return(await ForumViewResult.ViewResult(this, "Delay", viewModel)); }
public async Task <IActionResult> Edit(int id) { var record = await DbContext.Messages.SingleOrDefaultAsync(m => m.Id == id); if (record is null) { throw new HttpNotFoundError(); } var viewModel = new ViewModels.Messages.EditMessagePage { Id = id, Body = record.OriginalBody }; return(ForumViewResult.ViewResult(this, viewModel)); }