Exemplo n.º 1
0
        public ActionResult NewCard(NewHGSCardInDTO dto)
        {
            try
            {
                if (dto.Balance < 0 || dto.VehicleType == 0 || string.IsNullOrWhiteSpace(dto.VehiclePlate))
                {
                    TempData["Error"] = "Girdiğiniz bilgileri kontrol ediniz.";
                    return(Redirect($"/Hgs/NewCard"));
                }

                HGSCardTypeDTO card            = _externalService.GetCardTypes();
                decimal        customerBalance = _accountService.GetAccountBalance(dto.AccountId);
                decimal        totalPayment    = dto.Balance;
                switch (dto.VehicleType)
                {
                case 1:
                    totalPayment += card.CardPriceA;
                    break;

                case 2:
                    totalPayment += card.CardPriceB;
                    break;

                case 3:
                    totalPayment += card.CardPriceC;
                    break;

                default:
                    break;
                }
                if (customerBalance < totalPayment)
                {
                    TempData["Error"] = "Hesabınızda yeterli bakiye yok.";
                    return(Redirect($"/Hgs/NewCard"));
                }

                dto.CustomerId  = UserSession.Info.Id;
                dto.PaymentType = 1;
                dto.RequestDate = DateTime.Now;

                NewHGSCardResultDTO result = _externalService.NewHGSCard(dto);
                if (result.IsSuccess)
                {
                    TempData["Success"] = result.Message;
                    return(Redirect($"/Hgs/Index"));
                }
                else
                {
                    TempData["Error"] = "Girdiğiniz bilgileri kontrol ediniz.";
                    return(Redirect($"/Hgs/NewCard"));
                }
            }
            catch (Exception ex)
            {
                TempData["Error"] = "Girdiğiniz bilgileri kontrol ediniz.";
                return(Redirect($"/Hgs/NewCard"));
            }
        }
Exemplo n.º 2
0
        public HGSCardTypeDTO GetCardTypes()
        {
            HGSCardTypeDTO dto = new HGSCardTypeDTO();
            string         raw = HttpPostRequest($"/Payment/GetCardTypeList", null, null);

            dto = JsonConvert.DeserializeObject <HGSCardTypeDTO>(raw);

            return(dto);
        }
Exemplo n.º 3
0
        public HGSPaymentResultDTO HGSPayment(HGSPaymentInDTO payment)
        {
            HGSPaymentResultDTO result = new HGSPaymentResultDTO();

            using (BaseContext context = ContextFactory.Create())
            {
                IUnitOfWork           uow               = new BaseUnitOfWork(context);
                IRepository <HGSCard> cardRepository    = uow.GetRepository <HGSCard>();
                IRepository <Account> accountRepository = uow.GetRepository <Account>();

                HGSCard card = cardRepository.GetAll(x => x.Id == payment.CardId && x.Status == 1).FirstOrDefault();
                Dictionary <string, string> parameters = new Dictionary <string, string>();
                parameters.Add("CardNo", card.CardNo);
                parameters.Add("PaymentPrice", payment.Balance.ToString());
                parameters.Add("PaymentType", payment.PaymentType.ToString());
                parameters.Add("PaymentDate", payment.CreateDate.ToString());

                string       raw       = HttpPostRequest($"/Payment/DepositHGSCard", parameters, null);
                HGSResultDTO resultDTO = JsonConvert.DeserializeObject <HGSResultDTO>(raw);
                if (resultDTO.IsSuccess)
                {
                    card.Balance   += payment.Balance;
                    card.ModifyDate = DateTime.Now;

                    Account        acc      = accountRepository.GetAll(x => x.Id == payment.AccountId && x.Status == 1).FirstOrDefault();
                    HGSCardTypeDTO cardType = GetCardTypes();
                    acc.Balance -= payment.Balance;

                    uow.SaveChanges();
                }

                result.IsSuccess       = true;
                result.ResponseMessage = resultDTO.Message;
                return(result);
            }
        }
Exemplo n.º 4
0
        public NewHGSCardResultDTO NewHGSCard(NewHGSCardInDTO card)
        {
            NewHGSCardResultDTO result = new NewHGSCardResultDTO();

            using (BaseContext context = ContextFactory.Create())
            {
                IUnitOfWork            uow = new BaseUnitOfWork(context);
                IRepository <Customer> customerRepository = uow.GetRepository <Customer>();
                IRepository <HGSCard>  cardRepository     = uow.GetRepository <HGSCard>();
                IRepository <Account>  accountRepository  = uow.GetRepository <Account>();

                Customer cus = customerRepository.GetAll(x => x.Id == card.CustomerId && x.Status == 1).FirstOrDefault();

                Dictionary <string, string> parameters = new Dictionary <string, string>();
                parameters.Add("TCKN", cus.TCKN);
                parameters.Add("VehiclePlate", card.VehiclePlate);
                parameters.Add("VehicleType", card.VehicleType.ToString());
                parameters.Add("PaymentPrice", card.Balance.ToString());
                parameters.Add("PaymentType", card.PaymentType.ToString());
                parameters.Add("RequestDate", card.RequestDate.ToString());

                string raw = HttpPostRequest($"/Payment/BuyNewHGSCard", parameters, null);
                result = JsonConvert.DeserializeObject <NewHGSCardResultDTO>(raw);
                if (result.IsSuccess)
                {
                    HGSCard newCard = new HGSCard();
                    newCard.Balance      = card.Balance;
                    newCard.CardNo       = result.Data.CardNo;
                    newCard.ModifyDate   = DateTime.Now;
                    newCard.CreateDate   = result.Data.CreateDate;
                    newCard.CustomerId   = cus.Id;
                    newCard.Status       = 1;
                    newCard.VehiclePlate = card.VehiclePlate;
                    newCard.VehicleType  = card.VehicleType;
                    cardRepository.Add(newCard);

                    Account        acc          = accountRepository.GetAll(x => x.Id == card.AccountId && x.Status == 1).FirstOrDefault();
                    HGSCardTypeDTO cardType     = GetCardTypes();
                    decimal        totalPayment = card.Balance;
                    switch (card.VehicleType)
                    {
                    case 1:
                        totalPayment += cardType.CardPriceA;
                        break;

                    case 2:
                        totalPayment += cardType.CardPriceB;
                        break;

                    case 3:
                        totalPayment += cardType.CardPriceC;
                        break;

                    default:
                        break;
                    }

                    acc.Balance -= totalPayment;
                    uow.SaveChanges();
                }

                return(result);
            }
        }