Example #1
0
        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"));
            }
        }
Example #2
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);
            }
        }