//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(); }
public void CreateOrder(List <CartViewModel> cart, int accountId, int billingId) { foreach (var item in cart) { var newOrder = new OrderEntityModel { CustomerId = accountId, BookId = item.ItemId, Quantity = item.Quantity, BillingId = billingId, Price = item.Quantity * item.Price }; _db.Add(newOrder); //deletes the cart _cartService.RemoveCart(item, accountId); } var billing = GetBilling(billingId); //updates the cart to finished so this billing wont be changed var billingInput = new BillingEntityModel { Id = billingId, AccountId = accountId, StreetAddress = billing.StreetAddress, City = billing.City, Country = billing.Country, Finished = true, ZipCode = billing.ZipCode, CardOwner = billing.CardOwner, CardNumber = billing.CardNumber, ExpireDate = billing.ExpireMonth + "/" + billing.ExpireYear, CvCode = billing.CvCode }; _db.Update(billingInput); _db.SaveChanges(); }
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); } }