public IActionResult PayTicketWithPoints()
        {
            var    user        = UserManager.FindByNameAsync(User.Identity.Name).Result;
            var    partnerCode = CartRepository.GetPartnerCodeById(user.Id);
            var    res         = CartRepository.GetCartByUserId(user.Id);
            string hashValue   = HasherCard.Hash(partnerCode);

            double payed = 0;

            foreach (var item in res)
            {
                if (item.DiscountsByShow.DiscountId != "ninguno")
                {
                    var discount = CartRepository.GetDiscountById(item.DiscountsByShow.DiscountId);
                    payed += item.DiscountsByShow.Show.PriceInPoints - (item.DiscountsByShow.Show.PriceInPoints * discount.Percent / 100);
                }
                else
                {
                    payed += item.DiscountsByShow.Show.PriceInPoints;
                }
            }
            CartRepository.UdateRestPointsPartner(user.Id, payed);
            var payCart = new PayCart
            {
                DateTime    = DateTime.Now,
                UserId      = user.Id,
                CardHash    = hashValue,
                User        = user,
                PayCartId   = Guid.NewGuid().ToString(),
                PayedPoints = payed,
                PayedMoney  = 0
            };

            CartRepository.AddPayCart(payCart);
            foreach (var item in res)
            {
                var armChairByRoom     = CartRepository.GetArmChairByRoomById(item.ArmChairId, item.DiscountsByShow.ShowId);
                var userBoughtArmChair = CartRepository.GetUserBoughtArmChair(item.DiscountsByShow.ShowId, user.Id, armChairByRoom.ArmChairByRoomId);
                var pay = new Pay
                {
                    PayId                = Guid.NewGuid().ToString(),
                    PayCart              = payCart,
                    PayCartId            = payCart.PayCartId,
                    DiscountId           = item.DiscountsByShow.DiscountId,
                    UserBoughtArmChair   = userBoughtArmChair,
                    UserBougthArmChairId = userBoughtArmChair.UserBoughtArmChairId
                };
                CartRepository.AddPay(pay);
                CartRepository.DeleteCartById(item.CartId);
                Logger.LogInformation("Pay with money.");
            }
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public PayCart GetPayCartByHashCode(string hash)
        {
            if (hash == "伽�鑽購冝狃䪪䬐풽舠\u18acꅦ썭ﺙ伽")
            {
                return(null);
            }
            User user = new User
            {
                Role     = Roles.Client,
                Name     = "Valid",
                LastName = ":)"
            };
            PayCart payCart = new PayCart()
            {
                User        = user,
                CardHash    = "fghca",
                DateTime    = DateTime.Now,
                PayCartId   = Guid.NewGuid().ToString(),
                PayedMoney  = 2,
                PayedPoints = 1
            };

            return(payCart);
        }
        public IActionResult PayTicketWithMoney(PayTicketRequest request)
        {
            if (ModelState.IsValid)
            {
                var user = UserManager.FindByNameAsync(User.Identity.Name).Result;
                var res  = CartRepository.GetCartByUserId(user.Id);
                if (User.IsInRole(Roles.Partner))
                {
                    CartRepository.UdateAddPointsPartner(user.Id, res.Count * 5);
                }
                string hashValue = HasherCard.Hash(request.Card.ToString());

                double payed = 0;
                foreach (var item in res)
                {
                    if (item.DiscountsByShow.DiscountId != "ninguno")
                    {
                        var discount = CartRepository.GetDiscountById(item.DiscountsByShow.DiscountId);
                        payed += item.DiscountsByShow.Show.Price - (item.DiscountsByShow.Show.Price * discount.Percent / 100);
                    }
                    else
                    {
                        payed += item.DiscountsByShow.Show.Price;
                    }
                }
                //descontar de la tarjeta del usuario
                var payCart = new PayCart
                {
                    DateTime    = DateTime.Now,
                    UserId      = user.Id,
                    CardHash    = hashValue,
                    User        = user,
                    PayCartId   = Guid.NewGuid().ToString(),
                    PayedMoney  = payed,
                    PayedPoints = 0
                };
                CartRepository.AddPayCart(payCart);
                foreach (var item in res)
                {
                    var armChairByRoom     = CartRepository.GetArmChairByRoomById(item.ArmChairId, item.DiscountsByShow.ShowId);
                    var userBoughtArmChair = CartRepository.GetUserBoughtArmChair(item.DiscountsByShow.ShowId, user.Id, armChairByRoom.ArmChairByRoomId);
                    var pay = new Pay
                    {
                        PayId                = Guid.NewGuid().ToString(),
                        PayCart              = payCart,
                        PayCartId            = payCart.PayCartId,
                        DiscountId           = item.DiscountsByShow.DiscountId,
                        UserBoughtArmChair   = userBoughtArmChair,
                        UserBougthArmChairId = userBoughtArmChair.UserBoughtArmChairId
                    };
                    CartRepository.AddPay(pay);
                    CartRepository.DeleteCartById(item.CartId);
                }
                Logger.LogInformation("Pay with money.");
                return(RedirectToAction("Index"));
            }
            foreach (var error in ModelState.Values)
            {
                foreach (var item in error.Errors)
                {
                    Logger.LogError(item.ErrorMessage);
                }
            }
            return(RedirectToAction("Index"));
        }
 public void DeletePayCart(PayCart payCart)
 {
     _context.PayCart.Remove(payCart);
     _context.SaveChanges();
 }
 public void AddPayCart(PayCart pay)
 {
     _context.PayCart.Add(pay);
     _context.SaveChanges();
 }
Beispiel #6
0
 public void DeletePayCart(PayCart payCart)
 {
 }
Beispiel #7
0
        public List <Pay> GetPayByUserIdAndPayCartId(string userId, string payCartId)
        {
            string newPayCartId         = Guid.NewGuid().ToString();
            string PayId                = Guid.NewGuid().ToString();
            string discoutID            = Guid.NewGuid().ToString();
            string movieID              = Guid.NewGuid().ToString();
            string movieTypeID          = Guid.NewGuid().ToString();
            string room1ID              = Guid.NewGuid().ToString();
            string room2ID              = Guid.NewGuid().ToString();
            string showID               = Guid.NewGuid().ToString();
            string armChairID           = Guid.NewGuid().ToString();
            string armChairByRoomID     = Guid.NewGuid().ToString();
            string userBoughtArmChairID = Guid.NewGuid().ToString();

            User user = new User
            {
                Role     = Roles.Client,
                Name     = "Valid",
                LastName = ":)"
            };


            PayCart payCart = new PayCart()
            {
                User        = user,
                CardHash    = "zwxXyz",
                DateTime    = DateTime.Now,
                PayCartId   = newPayCartId,
                PayedMoney  = 1,
                PayedPoints = 1,
                UserId      = Guid.NewGuid().ToString()
            };

            MovieType movieType1 = new MovieType()
            {
                MovieTypeId = Guid.NewGuid().ToString(),
                Name        = "Crime"
            };

            Movie movie = new Movie()
            {
                MovieId     = movieID,
                DateUpload  = DateTime.Now,
                Name        = "The Godfather",
                Description = "An organized crime dynasty's aging patriarch transfers control of his clandestine empire to his reluctant son.",
                Director    = "Francis Ford Coppola",
                URL         = "https://localhost:44304/img/movie.jpg",
                MovieType   = movieType1,
                MovieTypeId = movieTypeID
            };

            Room room1 = new Room()
            {
                RoomId      = room1ID,
                Name        = "2B",
                NoArmChairs = 1
            };

            Room room2 = new Room()
            {
                RoomId      = room2ID,
                Name        = "A1",
                NoArmChairs = 2
            };

            Show show = new Show()
            {
                ShowId        = showID,
                DateTime      = DateTime.Now,
                Movie         = movie,
                MovieId       = movieID,
                Price         = 1,
                PriceInPoints = 1,
                Room          = room1,
                RoomId        = room1ID
            };

            ArmChair armChair = new ArmChair()
            {
                ArmChairId = armChairID,
                No         = 2
            };

            ArmChairByRoom armChairByRoom = new ArmChairByRoom()
            {
                ArmChairByRoomId = armChairByRoomID,
                ArmChairId       = armChairID,
                ArmChair         = armChair,
                RoomId           = room2ID,
                Room             = room2,
                StateArmChair    = StateArmChair.ready,
                Show             = show,
                ShowId           = show.ShowId
            };

            UserBoughtArmChair userBoughtArmChair = new UserBoughtArmChair()
            {
                UserBoughtArmChairId = userBoughtArmChairID,
                ArmChairByRoomId     = armChairByRoomID,
                ArmChairByRoom       = armChairByRoom,
                ShowId = showID,
                Show   = show,
                UserId = userId,
                User   = user
            };

            Discount discount1 = new Discount()
            {
                DiscountId = discoutID,
                Name       = "Black Friday",
                Percent    = 15
            };



            Pay pay = new Pay()
            {
                PayId                = PayId,
                PayCartId            = newPayCartId,
                DiscountId           = discoutID,
                Discount             = discount1,
                PayCart              = payCart,
                UserBougthArmChairId = userBoughtArmChairID,
                UserBoughtArmChair   = userBoughtArmChair
            };


            List <Pay> pays = new List <Pay>();

            pays.Add(pay);

            return(pays);
        }
Beispiel #8
0
 public void AddPayCart(PayCart pay)
 {
 }