Ejemplo n.º 1
0
        public async Task <IActionResult> Book(MovieProjectionViewModel movieProjectionViewModel, [FromRoute] int id)
        {
            if (!this.ModelState.IsValid)
            {
                var movieProjection = await this.movieProjectionsService
                                      .GetViewModelByIdAsync <MovieProjectionDetailsViewModel>(id);

                var soldSeats = await this.seatsService.GetAllSoldSeatsAsync(movieProjection.Hall.Id);

                var availableSeats = await this.seatsService.GetAllAvailableSeatsAsync(movieProjection.Hall.Id);

                var viewModel = new MovieProjectionViewModel
                {
                    MovieProjection = movieProjection,
                    SoldSeats       = soldSeats,
                    AvailableSeats  = availableSeats,
                    Ticket          = movieProjectionViewModel.Ticket,
                };

                return(this.Json(new
                {
                    Success = false,
                    Model = viewModel,
                    Message = ModelErrorsHelper.GetModelErrors(this.ModelState),
                }));
            }

            try
            {
                var result = await this.ticketsService.BuyAsync(movieProjectionViewModel.Ticket, id);

                return(this.Json(new
                {
                    Success = true,
                    Message = OperationalMessages.SuccessfullyBookedMovieProjection,
                }));
            }
            catch (ArgumentException aex)
            {
                return(this.Json(new { Success = false, Message = aex.Message }));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AjaxLogin(AjaxLoginInputModel loginInput, string returnUrl = null)
        {
            returnUrl = returnUrl ?? this.Url.Content("~/");

            var ajaxObject = new AjaxObject();

            if (this.ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await this.signInManager
                             .PasswordSignInAsync(loginInput.Username, loginInput.Password, loginInput.RememberMe, lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    this.logger.LogInformation("User logged in.");
                    ajaxObject.Success = true;
                    ajaxObject.Message = "Logged-in";
                    ajaxObject.Action  = returnUrl;
                }

                if (result.IsLockedOut)
                {
                    this.logger.LogWarning("This account has been locked out, please try again later.");
                    return(this.RedirectToPage("./Lockout"));
                }
                else
                {
                    this.ModelState.AddModelError(string.Empty, "The username or password supplied are incorrect. Please check your spelling and try again.");
                }
            }

            // login was unsuccessful, return model errors
            if (!ajaxObject.Success)
            {
                ajaxObject.Message = ModelErrorsHelper.GetModelErrors(this.ModelState);
            }

            var jsonResult = new JsonResult(ajaxObject);

            return(jsonResult);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> AjaxRegister(AjaxRegisterInputModel registerInput, string returnUrl = null)
        {
            returnUrl = returnUrl ?? this.Url.Content("~/");

            var ajaxObject = new AjaxObject();

            if (this.ModelState.IsValid)
            {
                Enum.TryParse <Gender>(registerInput.SelectedGender, out Gender gender);

                var user = new CinemaWorldUser
                {
                    UserName = registerInput.Username,
                    Email    = registerInput.Email,
                    FullName = registerInput.FullName,
                    Gender   = gender,
                };

                var result = await this.userManager.CreateAsync(user, registerInput.Password);

                if (result.Succeeded)
                {
                    this.logger.LogInformation("User created a new account with password.");
                    await this.userManager.AddToRoleAsync(user, GlobalConstants.UserRoleName);

                    ajaxObject.Success = true;
                    ajaxObject.Message = "Registered-in";
                    ajaxObject.Action  = returnUrl;

                    var code = await this.userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = this.Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code },
                        protocol: this.Request.Scheme);

                    await this.emailSender.SendEmailAsync(
                        registerInput.Email,
                        "Confirm your email",
                        htmlMessage : $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (this.userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(this.RedirectToPage("RegisterConfirmation", new { email = registerInput.Email }));
                    }
                    else
                    {
                        await this.signInManager.SignInAsync(user, isPersistent : false);
                    }
                }

                foreach (var error in result.Errors)
                {
                    this.ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            if (!ajaxObject.Success)
            {
                ajaxObject.Message = ModelErrorsHelper.GetModelErrors(this.ModelState);
            }

            var jsonResult = new JsonResult(ajaxObject);

            return(jsonResult);
        }