Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FullName,CartNo,Month,Year,CVV,UserId")] CreditCart creditCart)
        {
            if (id != creditCart.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(creditCart);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CreditCartExists(creditCart.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(Redirect("/Carts/PaymentDetail"));;
            }
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Email", creditCart.UserId);
            return(View(creditCart));
        }
Пример #2
0
        public IActionResult Add(CreditCart creditCart)
        {
            var result = _creditCartService.Add(creditCart);

            return(Ok(result));

            return(BadRequest(result));
        }
Пример #3
0
        public IActionResult Delete(CreditCart creditCart)
        {
            var result = _creditCartService.Delete(creditCart);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Пример #4
0
        public IResult MakePayment(CreditCart cart)
        {
            int random = new Random().Next(0, 2);

            if (random == 0)
            {
                return(new ErrorResult("Ödeme başarısız."));
            }
            return(new SuccessResult("Ödeme başarılı"));
        }
Пример #5
0
        public IResult CardVerification(CreditCart creditCart)
        {
            var result = _cartDal.Get(c => c.NameOnTheCard == creditCart.NameOnTheCard && c.CardCvv == creditCart.CardCvv && c.ExpirationMonth == c.ExpirationMonth && c.ExpirationYear == c.ExpirationYear);

            if (result == null)
            {
                return(new ErrorResult(Messages.NotFound));
            }
            return(new SuccessResult(Messages.CardMatched));
        }
        public IActionResult RegisterCreditCard(CreditCart creditCart)
        {
            var result = _cardService.Add(creditCart);

            if (result.Success)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
        public IActionResult Get(CreditCart creditCart)
        {
            var result = _cardService.CardVerification(creditCart);

            if (result.Success)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
Пример #8
0
        public async Task <IActionResult> Create([Bind("Id,FullName,CartNo,Month,Year,CVV,UserId")] CreditCart creditCart)
        {
            if (ModelState.IsValid)
            {
                _context.Add(creditCart);
                await _context.SaveChangesAsync();

                return(Redirect("/Cart/PaymentDetail"));
            }
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Email", creditCart.UserId);
            return(View(creditCart));
        }
Пример #9
0
        public IActionResult Payment(CreditCart creditCart)
        {
            var result = _creditCartService.MakePayment(creditCart);

            if (result.Success)
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result));
            }
        }
Пример #10
0
        public static BankResponse WithdrawFunds(CreditCart card, decimal amount)
        {
            // TODO: Actually implement bank api

            switch (card.Cvc)
            {
            case "100":
                return(BankResponse.Ok);

            case "200":
                return(BankResponse.NoMoney);

            default:
                return(BankResponse.Invalid);
            }
        }
Пример #11
0
        public IActionResult MakePayment(CreditCart creditCart)
        {
            var result = _paymentService.MakePayment(creditCart);

            return(StatusCode(result.Success ? 200 : 400, result));
        }
Пример #12
0
 public IResult Add(CreditCart creditCart)
 {
     _creditCartDal.Add(creditCart);
     return(new SuccessResult(Messages.CartAdded));
 }
Пример #13
0
 public IResult Update(CreditCart creditCart)
 {
     _cartDal.Update(creditCart);
     return(new SuccessResult(Messages.ProductUpdate));
 }
Пример #14
0
        public async Task <IActionResult> Continue(string phonenr, string address, string email, string ccname, string ccnumber, string ccexp, string cccvc)
        {
            var user = await _userManager.GetUserAsync(User);

            var cart = await _context.Carts
                       .Include(c => c.OrderedInventoryItems)
                       .ThenInclude(i => i.InventoryItem)
                       .SingleOrDefaultAsync(c => c.UserId == user.Id && !c.IsFinal);

            var invoice = new Invoice
            {
                Cart            = cart,
                CreationDate    = DateTime.Now,
                DeliveryAddress = address,
                Email           = email,
                Id          = Guid.NewGuid(),
                PaymentDate = DateTime.Now,
                PhoneNumber = phonenr
            };

            var cc = new CreditCart {
                Cvc = cccvc, CardNo = ccnumber, ExprirationDate = ccexp, FullName = ccname
            };

            switch (BankSystemApi.WithdrawFunds(cc, cart.TotalValue))
            {
            case BankResponse.Ok:
                break;

            case BankResponse.Invalid:
                return(View(new Invoice {
                    Cart = cart
                }));

            case BankResponse.NoMoney:
                return(View(new Invoice {
                    Cart = cart
                }));

            default:
                throw new ArgumentOutOfRangeException();
            }
            // Good

            cart.IsFinal = true;
            // Give 2 years warranty
            await _context.OrderedServiceItems.AddAsync(new OrderedServiceItem {
                CartId    = cart.Id,
                ServiceId = _context.ServiceItems.Single(s => s.Name == "Warranty").Id,
                StartDate = DateTime.Now,
                EndDate   = DateTime.Now.AddYears(2)
            });

            await _context.Invoices.AddAsync(invoice);

            await _context.SaveChangesAsync();

            SendEmail(invoice);

            return(RedirectToAction("Index"));
        }
Пример #15
0
 public IResult Delete(CreditCart creditCart)
 {
     _creditCartDal.Delete(creditCart);
     return(new SuccessResult(Messages.CartDeleted));
 }