コード例 #1
0
ファイル: HGSController.cs プロジェクト: saralonr/BankProject
        public ActionResult Detail(int cardId)
        {
            var customerId = UserSession.Info.Id;

            ViewBag.Accounts = _accountService.GetAllAccounts(customerId);
            HGSCard card = _externalService.GetHGSCardById(cardId, customerId);

            return(View(card));
        }
コード例 #2
0
        public HGSCard GetHGSCardById(int Id, int customerId)
        {
            HGSCard card = new HGSCard();

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

                card = cardRepository.GetAll(x => x.Id == Id && x.CustomerId == customerId && x.Status == 1).FirstOrDefault();
                return(card);
            }
        }
コード例 #3
0
        public IHttpActionResult BuyNewHGSCard(PurchaseRequest req)
        {
            try
            {
                if (CacheManager.PurchaseRequestList.Any(x => x.TCKN == req.TCKN && x.VehiclePlate == req.VehiclePlate))
                {
                    response.IsSuccess = false;
                    response.Message   = "Kişi aynı araç için birden fazla HGS ürününe sahip olamaz";
                    return(Json(response));
                }
                if (req.PaymentPrice < 0)
                {
                    response.IsSuccess = false;
                    response.Message   = "Geçersiz bir işlem yürütüldü.";
                    return(Json(response));
                }
                CacheManager.PurchaseRequestList.Add(req);
                HGSCard newCard = new HGSCard()
                {
                    Balance      = req.PaymentPrice,
                    CardNo       = GenerateCardTokenOptimised(),
                    CreateDate   = DateTime.Now,
                    GuidId       = Guid.NewGuid(),
                    ModifyDate   = DateTime.Now,
                    TCKN         = req.TCKN,
                    VehiclePlate = req.VehiclePlate,
                    VehicleType  = (int)req.VehicleType,
                    Status       = true
                };
                CacheManager.HGSCardList.Add(newCard);
                CacheManager.PaymentList.Add(new Payment()
                {
                    Card        = newCard,
                    PaymentDate = DateTime.Now,
                    PaymentType = req.PaymentType
                });

                response.IsSuccess = true;
                response.Message   = $"Satın alma başarıyla gerçekleştirildi. Hesabınıza {req.PaymentPrice} TL bakiye yüklendi.";
                response.Data      = newCard;
                return(Json(response));
            }
            catch (Exception)
            {
                response.IsSuccess = false;
                response.Message   = "Girdiğiniz bilgilerin doğruluğunu kontrol ediniz.";
                return(Json(""));
            }
        }
コード例 #4
0
ファイル: HGSController.cs プロジェクト: saralonr/BankProject
        public ActionResult CardPayment(HGSPaymentInDTO dto)
        {
            try
            {
                if (dto.Balance < 0)
                {
                    TempData["Error"] = "Girdiğiniz bilgileri kontrol ediniz.";
                    return(Redirect($"/Hgs/Detail/{dto.CardId}"));
                }

                var     customerId      = UserSession.Info.Id;
                HGSCard card            = _externalService.GetHGSCardById(dto.CardId, customerId);
                decimal customerBalance = _accountService.GetAccountBalance(dto.AccountId);

                if (customerBalance < dto.Balance)
                {
                    TempData["Error"] = "Hesabınızda yeterli bakiye yok.";
                    return(Redirect($"/Hgs/Detail/{dto.CardId}"));
                }

                dto.VehicleType = card.VehicleType;
                dto.CustomerId  = customerId;
                dto.CreateDate  = DateTime.Now;
                dto.PaymentType = 1;

                HGSPaymentResultDTO result = _externalService.HGSPayment(dto);
                if (result.IsSuccess)
                {
                    TempData["Success"] = result.ResponseMessage;
                    return(Redirect($"/Hgs/Index"));
                }
                else
                {
                    TempData["Error"] = "Girdiğiniz bilgileri kontrol ediniz.";
                    return(Redirect($"/Hgs/Detail/{dto.CardId}"));
                }
            }
            catch (Exception)
            {
                TempData["Error"] = "Girdiğiniz bilgileri kontrol ediniz.";
                return(Redirect($"/Hgs/Index"));
            }
        }
コード例 #5
0
        public HGSBalanceQueryResultDTO HGSBalanceQuery(string cardNo)
        {
            HGSCard card = new HGSCard();

            using (BaseContext context = ContextFactory.Create())
            {
                IUnitOfWork                 uow            = new BaseUnitOfWork(context);
                IRepository <HGSCard>       cardRepository = uow.GetRepository <HGSCard>();
                Dictionary <string, string> parameters     = new Dictionary <string, string>();
                parameters.Add("CardNo", cardNo);
                string raw = HttpPostRequest($"/Payment/GetBalanceFromCardNo?CardNo={cardNo}", parameters, null);
                HGSBalanceQueryResultDTO dto = JsonConvert.DeserializeObject <HGSBalanceQueryResultDTO>(raw);

                card            = cardRepository.GetAll(x => x.CardNo == cardNo && x.Status == 1).FirstOrDefault();
                card.Balance    = dto.Balance;
                card.ModifyDate = DateTime.Now;
                uow.SaveChanges();

                return(dto);
            }
        }
コード例 #6
0
        public IHttpActionResult DepositHGSCard(DepositCard req)
        {
            try
            {
                if (!CacheManager.HGSCardList.Any(x => x.CardNo == req.CardNo))
                {
                    response.IsSuccess = false;
                    response.Message   = "Kart bilgisi bulunamadı.";
                    return(Json(response));
                }
                if (req.PaymentPrice < 0)
                {
                    response.IsSuccess = false;
                    response.Message   = "Geçersiz bir işlem yürütüldü.";
                    return(Json(response));
                }

                HGSCard card = CacheManager.HGSCardList.Find(x => x.CardNo == req.CardNo);
                card.Balance += req.PaymentPrice;

                CacheManager.PaymentList.Add(new Payment()
                {
                    Card        = card,
                    PaymentDate = DateTime.Now,
                    PaymentType = req.PaymentType
                });

                response.IsSuccess = true;
                response.Message   = $"Yükleme başarıyla gerçekleştirildi. Hesabınıza {req.PaymentPrice} TL bakiye yüklendi.";
                return(Json(response));
            }
            catch (Exception)
            {
                response.IsSuccess = false;
                response.Message   = "Girdiğiniz bilgilerin doğruluğunu kontrol ediniz.";
                return(Json(response));
            }
        }
コード例 #7
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);
            }
        }
コード例 #8
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);
            }
        }