//Borgunin public bool BillingInfo(BillingInputModel info, string userId, int cartId) { if (userId == null) { return(false); } //bætir við nýrri borgunarleið //Á eftir að útfæra ef notandi hefur þegar gert pöntun og hann vill breyta //Get séð út frá nýjasta ID með pöntuninni hvað á að nota var userInfo = new BillingInfo { UserId = userId, Name = info.Name, Country = info.Country, Zipcode = info.Zipcode, City = info.City, Adress = info.Address, OrderId = cartId, PaymentMethod = info.PaymentMethod, CardNumber = info.CardNumber }; //ef ekkert kemur inn if (userInfo == null) { return(false); } //bætir við í gagnagrunninn _db.BillingInfos.Add(userInfo); _db.SaveChanges(); return(true); }
public void BillingInfo(BillingInputModel billing) { if (string.IsNullOrEmpty(billing.PaymentMethod)) { throw new Exception("Please enter a payment method"); } else if (string.IsNullOrEmpty(billing.CardNumber)) { throw new Exception("Please enter a valid cardnumber"); } }
public IActionResult BillingInfo(BillingInputModel billing) { if (!ModelState.IsValid) { return(View()); } var user = _userManager.GetUserId(User); var cartId = _orderServices.GetCart(user); if (!_orderServices.BillingInfo(billing, user, cartId)) { return(View("Error")); } return(RedirectToAction("ReviewOrder")); }
public IActionResult Billing(BillingInputModel billing) { string email = ((ClaimsIdentity)User.Identity).Name; int accountId = _accountService.GetAccountId(email); var userCart = _cartService.GetUserCartItems(accountId); if (ModelState.IsValid) { _checkoutService.CreateBilling(billing, accountId); var reviewOrder = _checkoutService.GetReviewOrder(billing, userCart); return(View("Review", reviewOrder)); } return(View()); }
//function creates a new billing public void CreateBillingHelperFunction(BillingInputModel billing, int accountId) { var billingInput = new BillingEntityModel { AccountId = accountId, StreetAddress = billing.StreetAddress, City = billing.City, Country = billing.Country, ZipCode = billing.ZipCode, Finished = false, CardOwner = billing.CardOwner, CardNumber = billing.CardNumber, ExpireDate = billing.ExpireMonth + "/" + billing.ExpireYear, CvCode = billing.CvCode }; _db.Add(billingInput); _db.SaveChanges(); }
//Gets the order to display during checkout public OrderViewModel GetReviewOrder(BillingInputModel billing, List <CartViewModel> userCart) { var price = new List <int>(); foreach (var item in userCart) { if (item.Quantity != 1) { price.Add(item.Price * item.Quantity); } else { price.Add(item.Price); } } return(new OrderViewModel { CartList = userCart, Billing = billing, TotalPrice = price.Sum() }); }
public void CreateBilling(BillingInputModel billing, int accountId) { if (BillingIdExist(accountId)) { //check wether the the existing billing has an order attached to it // if it doesnt exist built a new billing if (!OrderExist(accountId)) { CreateBillingHelperFunction(billing, accountId); } //else it updates the the old billing else { var billingInput = new BillingEntityModel { Id = GetBillingId(accountId), AccountId = accountId, StreetAddress = billing.StreetAddress, City = billing.City, Country = billing.Country, Finished = false, ZipCode = billing.ZipCode, CardOwner = billing.CardOwner, CardNumber = billing.CardNumber, ExpireDate = billing.ExpireMonth + "/" + billing.ExpireYear, CvCode = billing.CvCode }; _db.Update(billingInput); _db.SaveChanges(); } } else { CreateBillingHelperFunction(billing, accountId); } }