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")); } }
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); } }