public void CreateOrder(string firstName, string lastName, string address, string phone, string email)
        {
            Order order = new Order
            {
                Id        = Guid.NewGuid().ToString(),
                FirstName = firstName,
                LastName  = lastName,
                Address   = address,
                Phone     = phone,
                Email     = email,
                OrderDate = DateTime.UtcNow
            };

            autoShopDbContext.Order.Add(order);
            autoShopDbContext.SaveChanges();

            var items = autoShopCart.ListAutoShopItems;

            foreach (var element in items)
            {
                var orderDetail = new OrderDetail()
                {
                    CarId   = element.Car.Id,
                    OrderId = order.Id,
                    Price   = element.Car.Price
                };

                autoShopDbContext.OrderDetail.Add(orderDetail);
            }

            autoShopDbContext.SaveChanges();
        }
Exemplo n.º 2
0
 public void Save(Order order)
 {
     _autoShopDb.Add(order);
     foreach (var detail in order.OrderDetails)
     {
         _autoShopDb.Add(detail);
     }
     _autoShopDb.SaveChanges();
 }
Exemplo n.º 3
0
        public static void Initialize(AutoShopDbContext dbContext)
        {
            _ = dbContext ?? throw new ArgumentNullException(nameof(dbContext));

            if (!dbContext.Categories.Any())
            {
                dbContext.Categories.AddRange(CategoryConsts.Categories.Values);
                dbContext.SaveChanges();
            }

            if (!dbContext.Cars.Any())
            {
                var carsRepo = new MockCarRepository();
                dbContext.Cars.AddRange(carsRepo.GetAll());
                dbContext.SaveChanges();
            }
        }
Exemplo n.º 4
0
        public void AddToCart(Car car)
        {
            autoShopDbContext.AutoShopCartItem.Add(new AutoShopCartItem
            {
                AutoShopCartId = AutoShopCartId,
                Car            = car,
                Price          = car.Price
            });

            autoShopDbContext.SaveChanges();
        }
Exemplo n.º 5
0
 public void Save(OrderDetail orderDetail)
 {
     _autoShopDb.Add(orderDetail);
     _autoShopDb.SaveChanges();
 }
Exemplo n.º 6
0
 public void Save(CustomerCartItem cartItem)
 {
     _autoShopDb.Add(cartItem);
     _autoShopDb.SaveChanges();
 }
Exemplo n.º 7
0
 public void Save(CustomerCart cart)
 {
     _autoShopDb.CustomerCarts.Add(cart);
     _autoShopDb.SaveChanges();
 }
Exemplo n.º 8
0
 public void Save(Car car)
 {
     _autoShopDb.Add(car);
     _autoShopDb.SaveChanges();
 }