Пример #1
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="id"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        protected virtual bool UpdateShopcartCount(long id, int count)
        {
            var info = new ShopcartEntity
            {
                Id       = id,
                Count    = count,
                SaveType = SaveType.Modify
            };

            info.SetProperty(it => it.Count);
            return(this.SaveEntity(info));
        }
Пример #2
0
        public virtual ActionResult UpdateTag(long id, string tag)
        {
            var result = new Dictionary <string, object>();
            var info   = new ShopcartEntity
            {
                Id       = id,
                Tag      = tag,
                SaveType = SaveType.Modify
            };

            info.SetProperty(it => it.Tag);
            var rev = this.SaveEntity(info);

            result.Add("Status", rev);
            return(this.Jsonp(result));
        }
Пример #3
0
        public virtual ActionResult Add(int productId, string tag)
        {
            var result = new Dictionary <string, object>();
            var rev    = false;
            var query  = new QueryInfo();

            query.Query <ShopcartEntity>().Where(it => it.Product.Id == productId && it.Account.Id == Identity.Id)
            .Select(it => new object[] { it.Id, it.Count });
            var infos = this.GetEntities <ShopcartEntity>(query);

            if (infos != null && infos.Count > 0)
            {
                var info = infos.First();
                rev = UpdateShopcartCount(info.Id, info.Count + 1);
                result.Add("Id", info.Id);
                result.Add("Count", info.Count + 1);
            }
            else
            {
                var product = this.GetEntity <ProductEntity>(productId);
                if (product != null)
                {
                    var info = new ShopcartEntity
                    {
                        Tag     = tag,
                        Name    = product.Name,
                        Price   = product.Price,
                        Count   = 1,
                        Product = new ProductEntity {
                            Id = productId
                        },
                        Account = new AccountEntity {
                            Id = Identity.Id
                        },
                        SaveType = SaveType.Add
                    };
                    rev = this.SaveEntity(info);
                    result.Add("Id", info.Id);
                    result.Add("Count", info.Count);
                }
            }
            result.Add("Status", rev);

            return(this.Jsonp(result));
        }
Пример #4
0
        public virtual ActionResult Remove(long[] id)
        {
            var result = new Dictionary <string, object>();
            var rev    = false;

            if (id != null)
            {
                var infos = new List <ShopcartEntity>();
                foreach (var i in id)
                {
                    var info = new ShopcartEntity
                    {
                        Id       = i,
                        SaveType = SaveType.Remove
                    };
                    infos.Add(info);
                }
                rev = this.SaveEntities(infos);
            }
            result.Add("Status", rev);
            return(this.Jsonp(result));
        }