Ejemplo n.º 1
0
        public async Task <IActionResult> Create(AspNetUsers aspNetUsers)
        {
            var user = new ApplicationUser {
                UserName = aspNetUsers.UserName, Email = aspNetUsers.Email, PhoneNumber = aspNetUsers.PhoneNumber
            };
            var result = await _userManager.CreateAsync(user, "P@ssw0rd");

            if (result.Succeeded)
            {
                AspNetUserRoles userRole = new AspNetUserRoles()
                {
                    UserId = user.Id,
                    RoleId = _context.AspNetRoles.Where(r => r.Name == "CinemaAdmin").FirstOrDefault().Id
                };

                _context.AspNetUserRoles.Add(userRole);
                await _context.SaveChangesAsync();
            }
            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.UserName, Email = model.Email, PhoneNumber = model.PhoneNumber
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    AspNetUserRoles userRole = new AspNetUserRoles()
                    {
                        UserId = user.Id,
                        RoleId = _context.AspNetRoles.Where(r => r.Name == "SimpleUser").FirstOrDefault().Id
                    };

                    _context.AspNetUserRoles.Add(userRole);
                    await _context.SaveChangesAsync();

                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                    await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation("User created a new account with password.");
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <IActionResult> PayTickets()
        {
            try
            {
                var user = await GetCurrentUserAsync();

                if (user == null)
                {
                    return(BadRequest("There is no logged in user."));
                }

                var reservations = await _context.TblReservations
                                   .Include(t => t.ReservedInCinema)
                                   .Include(t => t.ReservedForMovie)
                                   .ThenInclude(t => t.ImageNavigation)
                                   .Where(r => r.ReservedByCustomerId == user.Id &&
                                          r.IsPaid == false &&
                                          r.ReservationStatusId == 2 &&
                                          r.IsDeleted == false).ToListAsync();

                if (reservations == null)
                {
                    return(BadRequest("Could not get reservations for user."));
                }

                decimal totalPrice = 0;

                foreach (var item in reservations)
                {
                    totalPrice += Convert.ToDecimal(item.ReservedForMovie.PriceForAdults);
                }

                ViewData["TotalPrice"] = totalPrice.ToString();

                foreach (var item in reservations)
                {
                    item.IsPaid              = true;
                    item.PaymentTypeId       = 2;
                    item.ReservationStatusId = 1;
                    _context.TblReservations.Update(item);
                    _context.Entry(item).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    TblTicket ticket = new TblTicket();
                    ticket.CustomerId           = user.Id;
                    ticket.CinemaId             = item.ReservedInCinema.CinemaId;
                    ticket.MovieId              = item.ReservedForMovie.MovieId;
                    ticket.Seat                 = item.Seat;
                    ticket.Price                = Convert.ToDecimal(item.ReservedForMovie.PriceForAdults);
                    ticket.TotalPrice           = Convert.ToDecimal(item.ReservedForMovie.PriceForAdults);
                    ticket.CreatedByUserId      = user.Id;
                    ticket.LastModifiedByUserId = user.Id;
                    ticket.CreatedOnDate        = DateTime.Now.ToShortDateString();
                    ticket.LastModifiedOnDate   = DateTime.Now.ToShortDateString();

                    await _context.TblTicket.AddAsync(ticket);

                    await _context.SaveChangesAsync();
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }