Пример #1
0
        public IActionResult CancelPay(long cardOrCode)
        {
            string hashValue = HasherCard.Hash(cardOrCode.ToString());
            var    payCart   = CartRepository.GetPayCartByHashCode(hashValue);

            if (payCart == null)
            {
                return(RedirectToAction("GetPayCarts"));
            }
            var user = UserManager.FindByNameAsync(User.Identity.Name).Result;
            var pays = CartRepository.GetPayByUserIdAndPayCartId(user.Id, payCart.PayCartId);

            if (user.Role == Roles.Partner && payCart.PayedPoints != 0)
            {
                var partner = CartRepository.GetPartnerByUserId(user.Id);
                partner.Points += payCart.PayedPoints;
                CartRepository.UpdatePartner(partner);
            }
            //devolver dinero
            CartRepository.DeletePayCart(payCart);
            foreach (var item in pays)
            {
                item.UserBoughtArmChair.ArmChairByRoom.StateArmChair = StateArmChair.ready;
                CartRepository.UpdateArmChairByRoom(item.UserBoughtArmChair.ArmChairByRoom);
                CartRepository.DeletePay(item);
            }
            return(RedirectToAction("GetPayCarts"));
        }
Пример #2
0
        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"));
        }
Пример #3
0
        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"));
        }