예제 #1
0
        public void UpdateBalance(Card card)
        {
            try
            {
                PaymentActivasionValidarior(card);
                MinimumBalanceValidator(card);
                card = CreateNotificasion(card);
                var crudCard = new CardCrud();
                crudCard.UpdateBalance(card);
                Payment payment = new Payment();
                payment.Date       = DateTime.Now;
                payment.IssuerUser = card.User;
                payment.Card       = card;
                payment.Amount     = card.newBalance;
                payment.Detail     = "Recarga de saldo del usario";
                Glosary glosary = new Glosary();
                glosary.PkIdTerm    = 4;
                payment.PaymentType = glosary;
                payment             = PayCrud.CreateParkingPayment(payment);
                PaymentTerminal py = new PaymentTerminal();
                py.PercentageUsed = 0;
                py.TerminalPayed  = card.Terminal;
                py.PaymentGot     = payment;

                PTCrud.Create(py);
            }
            catch (Exception ex)
            {
                ExceptionManager.GetInstance().Process(ex);
            }
        }
        /// <summary>
        /// Updates a ParkingBill
        /// </summary>
        /// <param name="pb"></param>
        public void UpdateParkingBill(ParkingBill pb)
        {
            try
            {
                ParkingBill exist = PBCrud.RetrieveParkingBillByCard <ParkingBill>(pb.ParkingCard);
                if (exist == null)
                {
                    throw new BusinessException(33);
                }
                exist.ParkedParking = PCrud.Retrieve <Parking>(exist.ParkedParking);
                exist.ParkingCard   = pb.ParkingCard;
                exist.EndDate       = pb.EndDate;
                exist.AmountHours   = Convert.ToInt32(Math.Round(exist.EndDate.Subtract(exist.BeginDate).TotalHours));

                if (exist.AmountHours > 8)
                {
                    exist.AmountHours = (exist.AmountHours / 24 + 1) * 24;
                }

                exist.TotalCost = exist.AmountHours * exist.ParkedParking.RentalCost;

                if (exist.ParkingCard.Balance - exist.TotalCost <= 0)
                {
                    throw new BusinessException(34);
                }

                exist.ParkingCard.Balance = exist.ParkingCard.Balance - exist.TotalCost;

                var payment = GetPayment(exist);
                payment = PYCrud.CreateParkingPayment(payment);

                var paymentTerminal = new PaymentTerminal
                {
                    Amount         = exist.TotalCost,
                    PercentageUsed = 0,
                    PaymentGot     = payment,
                    TerminalPayed  = exist.ParkingCard.Terminal,
                };

                PTCrud.Create(paymentTerminal);
                PBCrud.Update(exist);
                CCrud.UpdateBalance(exist.ParkingCard);
                exist.ParkedParking.OccupiedSpces -= 1;
                PCrud.ChangeOccupiedSpaces(exist.ParkedParking);
            }
            catch (Exception ex)
            {
                ExceptionManager.GetInstance().Process(ex);
            }
        }