示例#1
0
        public void Update(Model.Goods goods)
        {
            var dbContext = ServiceProvider.GetDbcontext <IPurocumentDbcontext>();
            var entity    = dbContext.Goods.SingleOrDefault(f => f.ID == goods.ID);

            if (entity == null)
            {
                throw new Exception("商品信息不存在");
            }
            if (entity.Disable)
            {
                throw new Exception("商品禁用无法修改");
            }
            if (string.IsNullOrEmpty(goods.Name))
            {
                throw new Exception("商品名称无效");
            }
            entity.Name          = goods.Name;
            entity.Desc          = goods.Desc;
            entity.Specification = goods.Specification;
            entity.ClassID       = goods.ClassID;
            entity.UnitID        = goods.UnitID;
            dbContext.Update(entity);
            dbContext.SaveChanges();
        }
示例#2
0
        public void AddGoods(Model.Goods goods)
        {
            if (goods == null)
            {
                throw new Exception("商品信息无效");
            }
            if (string.IsNullOrEmpty(goods.Name))
            {
                throw new Exception("商品名称无效");
            }
            var entity = new Entity.Goods()
            {
                Name    = goods.Name,
                ClassID = goods.ClassID,
                Disable = false,
                UnitID  = goods.UnitID
            };
            var dbContext = ServiceProvider.GetDbcontext <IPurocumentDbcontext>();

            dbContext.Add(entity);
            dbContext.SaveChanges();
        }