Ejemplo n.º 1
0
        public Order NewOrder(OrderRequest orderRequest)
        {
            using (TablesContext context = new TablesContext())
            {
                Order order = new Order
                {
                    UserId       = orderRequest.UserId,
                    TotalPayment = orderRequest.TotalPayment,
                    Status       = orderRequest.Status,
                };

                context.Orders.Add(order);
                context.SaveChanges();

                orderRequest.Books.ForEach(delegate(int book)
                {
                    BooksInOrder bookInOrder = new BooksInOrder
                    {
                        OrderId = context.Orders.ToList <Order>().Last().Id,
                        BookId  = book
                    };
                    context.BooksInOrders.Add(bookInOrder);
                    context.SaveChanges();
                });

                return(order);
            }
        }
Ejemplo n.º 2
0
        public void AddOrder(CheckOutInputModel info, string id)
        {
            var cart  = _cartService.GetCart(id);
            var order = new Order
            {
                UserId         = id,
                DateOfPurchase = System.DateTime.Today
            };

            var orderid = _orderRepo.WriteOrder(order);

            foreach (var n in cart)
            {
                var bio = new BooksInOrder
                {
                    OrderId  = orderid,
                    Title    = n.Title,
                    Price    = n.Price,
                    Quantity = n.Quantity
                };
                _orderRepo.AddBookOrderConnection(bio);
            }
            var cardNumber = "xxxxxxxxxxxx";

            cardNumber += info.CardNumber.Substring(12);
            var orderInfo = new OrderInfo
            {
                OrderId                = orderid,
                UserId                 = id,
                ShippingFirstName      = info.ShippingFirstName,
                ShippingLastName       = info.ShippingLastName,
                ShippingStreetName     = info.ShippingStreetName,
                ShippingHouseNumber    = info.ShippingHouseNumber,
                ShippingCity           = info.ShippingCity,
                ShippingZipCode        = info.ShippingZipCode,
                ShippingCountry        = info.ShippingCountry,
                BillingFirstName       = info.BillingFirstName,
                BillingLastName        = info.BillingLastName,
                BillingStreetName      = info.BillingStreetName,
                BillingHouseNumber     = info.BillingHouseNumber,
                BillingCity            = info.BillingCity,
                BillingZipCode         = info.BillingZipCode,
                BillingCounry          = info.BillingCountry,
                PaymentFullName        = info.FullName,
                PaymentCardNumber      = cardNumber,
                PaymentExpirationMonth = info.ExpirationMonth,
                PaymentExpirationYear  = info.ExpirationYear,
            };

            _orderRepo.AddOrderInfo(orderInfo);
            _cartService.ClearCart(id);
        }
Ejemplo n.º 3
0
 public void AddBookOrderConnection(BooksInOrder bio)
 {
     _db.Add(bio);
     _db.SaveChanges();
 }