public IResult Buy(BuyDto buyDto)
 {
     using (DataBaseContext contex = new DataBaseContext())
     {
         var creditCard = contex.Set <CreditCard>().SingleOrDefault(c => c.CardNumber == buyDto.CreditCardNumber &&
                                                                    c.SecurityNumber == buyDto.SecurityNumber &&
                                                                    c.MounthOfExpirationDate == buyDto.MounthOfExpirationDate &&
                                                                    c.YearOfExpirationDate == buyDto.YearOfExpirationDate);
         if (creditCard != null)
         {
             if (creditCard.Balance >= buyDto.Amount)
             {
                 creditCard.Balance -= buyDto.Amount;
                 var updateCreditCard = contex.Entry(creditCard);
                 updateCreditCard.State = EntityState.Modified;
                 contex.SaveChanges();
                 return(new SuccessResult());
             }
             return(new ErrorResult("Yetersiz Bakiye."));
         }
         else
         {
             return(new ErrorResult("Kart Bilgileri Hatalı."));
         }
     }
 }
        public IActionResult Refund(BuyDto buyDto)
        {
            var result = _creditCardService.Refund(buyDto);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result.Message));
        }
 public bool Refund(BuyDto buyDto)
 {
     using (DataBaseContext contex = new DataBaseContext())
     {
         var creditCard = contex.Set <CreditCard>().SingleOrDefault(c => c.CardNumber == buyDto.CreditCardNumber);
         creditCard.Balance += buyDto.Amount;
         var updateCreditCard = contex.Entry(creditCard);
         updateCreditCard.State = EntityState.Modified;
         contex.SaveChanges();
         return(true);
     }
 }
        public IResult Buy(BuyDto buyDto)
        {
            var result = _creditCardDal.Buy(buyDto);

            if (result.Success)
            {
                return(new SuccessResult());
            }
            else
            {
                return(new ErrorResult(result.Message));
            }
        }
Exemplo n.º 5
0
        static async Task <string> buyCurrency(string currency, double amount)
        {
            HttpClient client = new HttpClient();

            var    request     = new HttpRequestMessage(HttpMethod.Post, API_URL + "account/purchase");
            BuyDto contentJson = new BuyDto {
                Symbol = currency, Amount = amount
            };
            string        serializedObject = JsonConvert.SerializeObject(contentJson);
            StringContent content          = new StringContent(serializedObject, Encoding.UTF8, "application/json");

            request.Content = content;
            request.Headers.Add("X-Access-Token", SECRET_KEY);

            HttpResponseMessage response = await client.SendAsync(request);

            return(response.StatusCode.ToString());
        }
 public IResult Refund(BuyDto buyDto)
 {
     _creditCardDal.Refund(buyDto);
     return(new SuccessResult());
 }