Exemple #1
0
 /// <summary>
 /// 注册用户
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public int RegisterUser(UserInfo user)
 {
     using (ECContext ctx = new ECContext())
     {
         ctx.UserInfo.Add(user);
         return(ctx.SaveChanges());
     }
 }
 /// <summary>
 /// 新增商品
 /// </summary>
 /// <param name="pro"></param>
 /// <returns></returns>
 public int AddProduct(Product pro)
 {
     using (ECContext ctx = new ECContext())
     {
         ctx.Product.Add(pro);
         return(ctx.SaveChanges());
     }
 }
Exemple #3
0
        public bool AddProduct(string title)
        {
            var item = new ProductEntity(title: title);

            _context.Products.Add(item);
            _context.SaveChanges();

            return(true);
        }
 /// <summary>
 /// 删除商品
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public int DeleteProduct(int id)
 {
     using (ECContext ctx = new ECContext())
     {
         Product pro = ctx.Product.First(m => m.PId == id);
         ctx.Product.Remove(pro);
         return(ctx.SaveChanges());
     }
 }
 /// <summary>
 /// 修改商品
 /// </summary>
 /// <param name="pro"></param>
 /// <returns></returns>
 public int UpdateProduct(Product pro)
 {
     using (ECContext ctx = new ECContext())
     {
         ctx.Product.Attach(pro);
         ctx.Entry(pro).State = EntityState.Modified;
         return(ctx.SaveChanges());
     }
 }
Exemple #6
0
        public void CreateOrder()
        {
            try
            {
                using (ECContext context = new ECContext())
                {
                    Console.WriteLine("开始生成订单");
                    RedisProduct caceh   = new RedisProduct();
                    var          product = context.Product.FirstOrDefault(p => p.Id == ProductId);

                    Thread.Sleep(5000);
                    //var cacheProduct = caceh.Get(product.Id.ToString());
                    Order model = new Order()
                    {
                        Id         = Guid.NewGuid().ToString(),
                        CreateTime = DateTime.Now,
                        OrderNo    = OrderNo,
                        OrderItem  = new List <OrderItem>(),
                    };
                    model.OrderItem.Add(new OrderItem()
                    {
                        Count = Count, Id = Guid.NewGuid().ToString(), Product = product, Order = model
                    });
                    //if (cacheProduct.Count <= Count)
                    //{
                    //    throw new Exception("库存不足");
                    //}
                    caceh.LockStore(product.Id.ToString(), Count);
                    context.Order.Add(model);
                    context.SaveChanges();
                    //cacheProduct.Count -= Count;
                    //caceh.UpdateCache(product.Id.ToString(), cacheProduct);

                    Console.WriteLine("下单完成");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "," + ex.StackTrace);
            }
        }