Exemple #1
0
        private IActionResult redirectAccordingToState(string userType, LoginModel model)
        {
            try
            {
                switch (userType)
                {
                case "Buyer":
                    return(RedirectToAction("Index", "Buyer"));

                case "Seller":
                    if (!_serviceFacade.ChangeUserState(new Guid(HttpContext.Session.Id), "SellerUserState"))
                    {
                        ModelState.AddModelError("Incorrect User type", "Incorrect User type");
                        _serviceFacade.Logout(new Guid(HttpContext.Session.Id));
                        return(View(model));
                    }
                    return(RedirectToAction("Index", "Seller"));

                case "Admin":
                    if (!_serviceFacade.ChangeUserState(new Guid(HttpContext.Session.Id), "AdminUserState"))
                    {
                        ModelState.AddModelError("Incorrect User type", "Incorrect User type");
                        _serviceFacade.Logout(new Guid(HttpContext.Session.Id));
                        return(View(model));
                    }
                    return(RedirectToAction("Index", "Admin"));

                default:
                    ModelState.AddModelError("an error occured", "an error occured");
                    return(View(model));
                }
            }
            catch (GeneralServerError)
            {
                var redirect = this.Url.Action("Index", "Home");
                var message  = new UserMessage(redirect, "An error has occured. Please refresh and try again.");
                return(View("UserMessage", message));
            }
            catch (DatabaseConnectionTimeoutException)
            {
                var redirect = this.Url.Action("Index", "Home");
                var message  = new UserMessage(redirect, "An error has occured. Please refresh and try again. (Database connection lost).");
                return(View("UserMessage", message));
            }
        }
Exemple #2
0
 public bool ChangeUserState(Guid userGuid, string newState)
 {
     return(_serviceFacade.ChangeUserState(userGuid, newState));
 }