示例#1
0
        public static bool Delete(string id)
        {
            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    ShopCars model = context.ShopCars.Find(id);

                    if (model != null)
                    {
                        context.ShopCars.Remove(model);
                        context.SaveChanges();
                        return(false);
                    }
                }
            }

            return(false);
        }
示例#2
0
        public bool Add()
        {
            if (this.Valid())
            {
                this.Id      = General.UniqueString(this.Id);
                this.AddDate = DateTime.Now;

                using (WMContext context = new WMContext())
                {
                    ShopCars model = (
                        from car in context.ShopCars
                        where car.UserId.Equals(this.UserId) &&
                        car.GoodId.Equals(this.GoodId)
                        select car
                        ).FirstOrDefault();

                    if (model != null)
                    {
                        model.Price  = this.Price;
                        model.Count += this.Count;
                    }
                    else
                    {
                        model = new ShopCars {
                            Id      = this.Id,
                            GoodId  = this.GoodId,
                            UserId  = this.UserId,
                            Price   = this.Price,
                            Count   = this.Count,
                            AddDate = this.AddDate
                        };

                        context.ShopCars.Add(model);
                    }

                    context.SaveChanges();
                }

                return(true);
            }

            return(false);
        }
示例#3
0
        public static bool UpdateCount(string id, int count = 1)
        {
            if (!General.IsNullable(id))
            {
                using (WMContext context = new WMContext())
                {
                    ShopCars model = context.ShopCars.Find(id);

                    if (model != null)
                    {
                        if ((model.Count + count) > 0)
                        {
                            model.Count += count;
                            context.SaveChanges();
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
示例#4
0
        /// <summary>
        /// 添加新的购物车信息,如果购物信息已存在,则追加相应购买数量
        /// </summary>
        /// <returns>操作成功返回True,否则返回False</returns>
        public bool Add()
        {
            if (this.Valid())
            {
                this.Id = General.UniqueString(this.Id);
                this.AddDate = DateTime.Now;

                using (WMContext context = new WMContext())
                {
                    ShopCars model = (
                        from car in context.ShopCars
                        where car.UserId.Equals(this.UserId)
                           && car.GoodId.Equals(this.GoodId)
                        select car
                    ).FirstOrDefault();

                    if (model != null)
                    {
                        model.Price = this.Price;
                        model.Count += this.Count;
                    }
                    else
                    {
                        model = new ShopCars {
                            Id = this.Id,
                            GoodId = this.GoodId,
                            UserId = this.UserId,
                            Price = this.Price,
                            Count = this.Count,
                            AddDate = this.AddDate
                        };

                        context.ShopCars.Add(model);
                    }

                    context.SaveChanges();
                }

                return true;
            }

            return false;
        }