Exemplo n.º 1
0
        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); }));
            }
        }
Exemplo n.º 2
0
        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));
            }
        }
Exemplo n.º 3
0
        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));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> MarkUnread(int id)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = TopicRepository.MarkUnread(id);
                return(await ForumViewResult.RedirectFromService(this, serviceResponse));
            }

            return(ForumViewResult.RedirectToReferrer(this));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> MarkAllRead()
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = TopicRepository.MarkAllRead();
                return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailToReferrer));
            }

            return(await FailToReferrer());
        }
Exemplo n.º 6
0
        public async Task <IActionResult> AddThought(int id, int smiley)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await MessageRepository.AddThought(id, smiley);

                return(await ForumViewResult.RedirectFromService(this, serviceResponse));
            }

            return(ForumViewResult.RedirectToReferrer(this));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Delete(int id)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await MessageRepository.DeleteMessage(id);

                return(await ForumViewResult.RedirectFromService(this, serviceResponse));
            }

            return(ForumViewResult.RedirectToReferrer(this));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> SendVerificationEmail()
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await AccountRepository.SendVerificationEmail();

                return(await ForumViewResult.RedirectFromService(this, serviceResponse, failSync : FailureCallback));
            }

            return(FailureCallback());

            IActionResult FailureCallback() => RedirectToAction(nameof(Account.Details), nameof(Account));
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Latest(int id)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = TopicRepository.GetLatest(id);
                return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback));
            }

            return(await FailureCallback());

            async Task <IActionResult> FailureCallback()
            {
                return(await Task.Run(() => { return ForumViewResult.RedirectToReferrer(this); }));
            }
        }
Exemplo n.º 11
0
        public async Task <IActionResult> AddThought(InputModels.ThoughtInput input)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await MessageRepository.AddThought(input);

                return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback));
            }

            return(await FailureCallback());

            async Task <IActionResult> FailureCallback()
            {
                return(await Task.Run(() => { return ForumViewResult.RedirectToReferrer(this); }));
            }
        }
Exemplo n.º 12
0
        public async Task <IActionResult> SendVerificationEmail()
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await AccountRepository.SendVerificationEmail();

                return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback));
            }

            return(await FailureCallback());

            async Task <IActionResult> FailureCallback()
            {
                return(await Task.Run(() => { return RedirectToAction(nameof(Profile.Details), nameof(Profile)); }));
            }
        }
Exemplo n.º 13
0
        public async Task <IActionResult> UpdateAvatar(InputModels.UpdateAvatarInput input)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await AccountRepository.UpdateAvatar(input);

                return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback));
            }

            return(await FailureCallback());

            async Task <IActionResult> FailureCallback()
            {
                var userRecord = input.Id is null ? UserContext.ApplicationUser : await UserManager.FindByIdAsync(input.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
                };

                return(await ForumViewResult.ViewResult(this, nameof(Details), viewModel));
            }
        }
Exemplo n.º 14
0
        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()
            {
                return(await Task.Run(() => {
                    var classicLogin = Url.Action(nameof(LoginClassic));
                    return ForumViewResult.RedirectToLocal(this, classicLogin);
                }));
            }
        }
Exemplo n.º 15
0
        public async Task <IActionResult> Reply(InputModels.MessageInput input)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await MessageRepository.CreateReply(input);

                if (input.SideLoad)
                {
                    foreach (var kvp in serviceResponse.Errors)
                    {
                        ModelState.AddModelError(kvp.Key, kvp.Value);
                    }
                }
                else
                {
                    return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback));
                }
            }

            if (input.SideLoad)
            {
                var errors = ModelState.Keys.Where(k => ModelState[k].Errors.Count > 0).Select(k => new { propertyName = k, errorMessage = ModelState[k].Errors[0].ErrorMessage });
                return(new JsonResult(errors));
            }
            else
            {
                return(await FailureCallback());
            }

            async Task <IActionResult> FailureCallback()
            {
                ViewData["Smileys"] = await SmileyRepository.GetSelectorList();

                var viewModel = new ViewModels.Messages.ReplyForm {
                    Id        = input.Id.ToString(),
                    Body      = input.Body,
                    ElementId = $"message-reply-{input.Id}"
                };

                return(await ForumViewResult.ViewResult(this, viewModel));
            }
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Create(InputModels.MessageInput input)
        {
            if (ModelState.IsValid)
            {
                if (Request.Method == "GET" && input.BoardId != null)
                {
                    input.SelectedBoards.Add((int)input.BoardId);
                }
                else
                {
                    foreach (var board in await BoardRepository.Records())
                    {
                        if (Request.Form.TryGetValue("Selected_" + board.Id, out var boardSelected))
                        {
                            if (boardSelected == "True")
                            {
                                input.SelectedBoards.Add(board.Id);
                            }
                        }
                    }
                }

                var serviceResponse = await MessageRepository.CreateTopic(input);

                return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback));
            }

            return(await FailureCallback());

            async Task <IActionResult> FailureCallback()
            {
                ViewData["Smileys"] = await SmileyRepository.GetSelectorList();

                var viewModel = new ViewModels.Messages.CreateTopicForm {
                    Id      = "0",
                    BoardId = input.BoardId.ToString(),
                    Body    = input.Body
                };

                return(await ForumViewResult.ViewResult(this, viewModel));
            }
        }
Exemplo n.º 17
0
        public async Task <IActionResult> TopicReply(InputModels.MessageInput input)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await MessageRepository.CreateReply(input);

                return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback));
            }

            return(await FailureCallback());

            async Task <IActionResult> FailureCallback()
            {
                var viewModel = GetDisplayPageModel(input.Id);

                viewModel.ReplyForm.Body = input.Body;

                return(await Task.Run(() => { return ForumViewResult.ViewResult(this, nameof(Display), viewModel); }));
            }
        }
Exemplo n.º 18
0
        public async Task <IActionResult> Edit(InputModels.MessageInput input)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await MessageRepository.EditMessage(input);

                return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback));
            }

            return(await FailureCallback());

            async Task <IActionResult> FailureCallback()
            {
                var viewModel = new ViewModels.Messages.CreateTopicPage {
                    Body = input.Body
                };

                return(await Task.Run(() => { return ForumViewResult.ViewResult(this, viewModel); }));
            }
        }
Exemplo n.º 19
0
        public async Task <IActionResult> Edit(InputModels.MessageInput input)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await MessageRepository.EditMessage(input);

                if (input.SideLoad)
                {
                    foreach (var kvp in serviceResponse.Errors)
                    {
                        ModelState.AddModelError(kvp.Key, kvp.Value);
                    }
                }
                else
                {
                    return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback));
                }
            }

            if (input.SideLoad)
            {
                var errors = ModelState.Keys.Where(k => ModelState[k].Errors.Count > 0).Select(k => new { propertyName = k, errorMessage = ModelState[k].Errors[0].ErrorMessage });
                return(new JsonResult(errors));
            }
            else
            {
                return(await FailureCallback());
            }

            async Task <IActionResult> FailureCallback()
            {
                var viewModel = new ViewModels.Messages.CreateTopicForm {
                    Id        = "0",
                    Body      = input.Body,
                    ElementId = "create-topic"
                };

                return(await ForumViewResult.ViewResult(this, viewModel));
            }
        }
Exemplo n.º 20
0
        public async Task <IActionResult> Create(InputModels.MessageInput input)
        {
            if (ModelState.IsValid)
            {
                if (Request.Method == "GET" && input.BoardId != null)
                {
                    input.SelectedBoards.Add((int)input.BoardId);
                }
                else
                {
                    foreach (var board in BoardRepository)
                    {
                        if (Request.Form.TryGetValue("Selected_" + board.Id, out var boardSelected))
                        {
                            if (boardSelected == "True")
                            {
                                input.SelectedBoards.Add(board.Id);
                            }
                        }
                    }
                }

                var serviceResponse = await MessageRepository.CreateTopic(input);

                return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback));
            }

            return(await FailureCallback());

            async Task <IActionResult> FailureCallback()
            {
                var viewModel = new ViewModels.Messages.CreateTopicPage()
                {
                    BoardId = input.BoardId,
                    Body    = input.Body
                };

                return(await Task.Run(() => { return ForumViewResult.ViewResult(this, viewModel); }));
            }
        }
Exemplo n.º 21
0
        public async Task <IActionResult> ResetPassword(InputModels.ResetPasswordInput input)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await AccountRepository.ResetPassword(input);

                return(await ForumViewResult.RedirectFromService(this, serviceResponse, FailureCallback));
            }

            return(await FailureCallback());

            async Task <IActionResult> FailureCallback()
            {
                await AccountRepository.SignOut();

                var viewModel = new ViewModels.Account.ResetPasswordPage {
                    Code = input.Code
                };

                return(ForumViewResult.ViewResult(this, viewModel));
            }
        }
Exemplo n.º 22
0
        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 = (await AccountRepository.Records()).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),
                    BirthdayDay      = input.BirthdayDay.ToString(),
                    BirthdayMonth    = input.BirthdayMonth.ToString(),
                    FrontPage        = userRecord.FrontPage,
                    FrontPageOptions = FrontPagePickList(userRecord.FrontPage),
                    MessagesPerPage  = userRecord.MessagesPerPage,
                    PopularityLimit  = userRecord.PopularityLimit,
                    Poseys           = userRecord.Poseys,
                    ShowFavicons     = userRecord.ShowFavicons,
                    TopicsPerPage    = userRecord.TopicsPerPage
                };

                return(await ForumViewResult.ViewResult(this, viewModel));
            }
        }
Exemplo n.º 23
0
        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 {
                    DisplayName = input.DisplayName,
                    Email       = input.Email,
                    Password    = input.Password,
                };

                return(await ForumViewResult.ViewResult(this, viewModel));
            }
        }
Exemplo n.º 24
0
        public async Task <IActionResult> FinishMerge(int sourceId, int targetId)
        {
            var serviceResponse = await TopicRepository.Merge(sourceId, targetId);

            return(await ForumViewResult.RedirectFromService(this, serviceResponse));
        }