public SalesOrder CreateOrder(SalesOrder orderToCreate)
        {
            _orderingContext.Attach(orderToCreate);

            _orderingContext.SalesOrders.Add(orderToCreate);

            _orderingContext.SaveChanges();

            return(orderToCreate);
        }
Esempio n. 2
0
        public object Add(Domain.Table item)
        {
            var entity = EntityFrom(item);

            logger.Log(context, "Table", "Add", entity);

            context.Tables.Add(entity);
            context.SaveChanges();
            return(entity.Id);
        }
Esempio n. 3
0
        public object Add(Domain.Order item)
        {
            if (item.Closed)
            {
                throw new InvalidOperationException("A new order cannot be marked as closed");
            }

            var entity = EntityFrom(item);

            logger.Log(context, "Order", "Add", entity);

            context.Orders.Add(entity);
            context.SaveChanges();
            return(entity.Id);
        }
Esempio n. 4
0
 //添加订单操作
 public static void AddOrder(Order order)
 {
     //if (orders.Contains(order))
     //{
     //    throw new ApplicationException($"the order {order.OrderId} already exists!");
     //}
     //orders.Add(order);
     using (var db = new OrderingContext())
     {
         db.Entry(order).State = EntityState.Added;
         db.SaveChanges();
     }
 }
        //private readonly IFeatureService featureService;

        public OrderingControllerTest()
        {
            dbContextOptions = new DbContextOptionsBuilder <OrderingContext>()
                               .UseInMemoryDatabase(databaseName: "in-memory")
                               .Options;

            using (var dbContext = new OrderingContext(dbContextOptions))
            {
                dbContext.AddRange(GetFakeData());
                dbContext.SaveChanges();
            }
            logger = new Mock <ILogger <OrderingController> >().Object;
            //
        }
Esempio n. 6
0
        public static void SeedOrderStatus(
            OrderingContext context,
            Guid id,
            Guid orderStateId,
            int order,
            string enName,
            string deName,
            string plName)
        {
            if (!context.OrderStatuses.Any(x => x.Id == id && x.IsActive))
            {
                var orderStatus = new OrderStatus
                {
                    Id           = id,
                    Order        = order,
                    OrderStateId = orderStateId
                };

                context.OrderStatuses.Add(orderStatus.FillCommonProperties());

                var enOrderStatusTranslation = new OrderStatusTranslation
                {
                    Name          = enName,
                    OrderStatusId = orderStatus.Id,
                    Language      = "en"
                };

                var deOrderStatusTranslation = new OrderStatusTranslation
                {
                    Name          = deName,
                    OrderStatusId = orderStatus.Id,
                    Language      = "de"
                };


                var plOrderStatusTranslation = new OrderStatusTranslation
                {
                    Name          = plName,
                    OrderStatusId = orderStatus.Id,
                    Language      = "pl"
                };

                context.OrderStatusTranslations.Add(enOrderStatusTranslation.FillCommonProperties());
                context.OrderStatusTranslations.Add(deOrderStatusTranslation.FillCommonProperties());
                context.OrderStatusTranslations.Add(plOrderStatusTranslation.FillCommonProperties());

                context.SaveChanges();
            }
        }
Esempio n. 7
0
 //删除订单操作
 public static void RemoveOrder(int orderId)
 {
     //orders.RemoveAll(o => o.OrderId == orderId);
     using (var db = new OrderingContext())
     {
         var order = db.Orders.Include("OrderDetails").SingleOrDefault(o => o.OrderId == orderId);
         if (order == null)
         {
             return;
         }
         db.OrderDetails.RemoveRange(order.Goods);
         db.Orders.Remove(order);
         db.SaveChanges();
     }
 }
Esempio n. 8
0
        private static void SeedOrderState(OrderingContext context, Guid id, string name)
        {
            if (!context.OrderStates.Any(x => x.Id == id && x.IsActive))
            {
                var orderState = new OrderState
                {
                    Id   = id,
                    Name = name
                };

                context.OrderStates.Add(orderState.FillCommonProperties());

                context.SaveChanges();
            }
        }
        public ActionResult Delete(int id, FormCollection collection)
        {
            using (OrderingContext context = new OrderingContext())
                try
                {
                    Customer customer = context.Customers.Find(id);
                    context.Customers.Remove(customer);
                    context.SaveChanges();


                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View());
                }
        }
        public ActionResult Create(Customer customer)
        {
            try
            {
                using (OrderingContext context = new OrderingContext())
                {
                    context.Customers.Add(customer);
                    context.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Edit(int id, Customer customer)
        {
            //customer.FirstName = "Test";

            try
            {
                using (OrderingContext context = new OrderingContext())
                {
                    context.Entry(customer).State = EntityState.Modified;
                    context.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 12
0
        public static void Import(string filepath)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <Order>));

            using (FileStream fs = new FileStream(filepath, FileMode.Open))
            {
                using (var db = new OrderingContext())
                {
                    List <Order> temp = (List <Order>)xmlSerializer.Deserialize(fs);
                    temp.ForEach(order => {
                        if (db.Orders.SingleOrDefault(o => o.OrderId == order.OrderId) == null)
                        {
                            db.Orders.Add(order);
                        }
                    });
                    db.SaveChanges();
                }
            }
        }
Esempio n. 13
0
 public void Add(Order order)
 {
     _context.Orders.Add(order);
     _context.SaveChanges();
 }
Esempio n. 14
0
        public static void Initialize(OrderingContext context)
        {
            context.Database.EnsureCreated();

            if (context.Order.Any())
            {
                return;
            }

            var orders = new Order[]
            {
                //new Order{Date= new DateTime(1991, 12, 31, 22, 56, 59), Sum = 3000, UserId = 1, User=context.User.FirstOrDefault()},
                // new Order{Date= new DateTime(2000, 12, 31, 22, 56, 59),Sum = 10000, UserId = 2, User=context.User.FirstOrDefault()},
                // new Order{Url="http://orders.msdn.com/visualstudio"}
            };

            foreach (Order b in orders)
            {
                context.Order.Add(b);
            }
            context.SaveChanges();

            var products = new Product[]
            {
                new Product {
                    Name = "Спортивная куртка на молнии", Costs = 3000
                },
                new Product {
                    Name = "Спортивный зимний костюм", Costs = 5000
                }
            };

            foreach (Product p in products)
            {
                context.Product.Add(p);
            }
            var users = new User[]
            {
                // new User { Username="******",Email = "*****@*****.**" },
                // new User { Username="******",Email = "*****@*****.**"  }
            };

            foreach (User p in users)
            {
                context.User.Add(p);
            }
            context.SaveChanges();

            var os = new OrderString[]
            {
                new OrderString {
                    OrderId = 1, ProductId = 1, Cost = 3000, Count = 1
                },
                new OrderString {
                    OrderId = 2, ProductId = 2, Cost = 10000, Count = 2
                }
            };

            foreach (OrderString p in os)
            {
                context.OrderString.Add(p);
            }
            context.SaveChanges();
        }