private void ProcessOrder(ShoppingCartModel cart) { string idString = System.Web.HttpContext.Current.User.Identity.Name; //int customerId = int.Parse(idString); int customerId = 7020; Customer customer = db.Customers.SingleOrDefault(c => c.CustomerID == customerId); customer.CustomerFirstName = cart.BillingInfo.FirstName; customer.CustomerLastName = cart.BillingInfo.LastName; customer.BillingAddress = cart.BillingInfo.Address; customer.BillingCity = cart.BillingInfo.City; customer.BillingState = cart.BillingInfo.State; customer.BillingPostalCode = cart.BillingInfo.PostalCode; customer.BillingCreditCardNumber = cart.BillingInfo.CreditCardNumber; customer.BillingExpireMonth = cart.BillingInfo.ExpireMonth; customer.BillingExpireYear = cart.BillingInfo.ExpireYear; db.SaveChanges(); Order order = new Order { CustomerID = customer.CustomerID, OrderDate = DateTime.Now, ShippingAddress = cart.ShippingInfo.Address, ShippingCity = cart.ShippingInfo.City, ShippingState = cart.ShippingInfo.State, ShippingPostalCode = cart.ShippingInfo.PostalCode }; db.Orders.Add(order); db.SaveChanges(); foreach (ShoppingCartItemModel item in cart.Items) { OrderDetail orderItem = new OrderDetail { OrderID = order.OrderID, ProductID = item.Product.ProductID, OrderDetailQuotedPrice = item.Product.ProductPrice, OrderDetailQuantityOrdered = item.Quantity }; db.OrderDetails.Add(orderItem); } db.SaveChanges(); }
public RedirectToRouteResult Register(Customer customer) { customer.Password = SHA256.Encode(customer.CustomerPassword); db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index", "Home")); }