Ejemplo n.º 1
0
        public async Task <ActionResult> Edit(GoodsAddEditModel model)
        {
            if (string.IsNullOrEmpty(model.Description))
            {
                model.Description = "";
            }
            if (model.Inventory < 0)
            {
                return(Json(new AjaxResult {
                    Status = 0, Msg = "库存不能小于零"
                }));
            }
            if (model.GoodsSecondTypeId == null)
            {
                model.GoodsSecondTypeId = await goodsSecondTypeService.GetIdByNameAsync("空类型");
            }
            bool flag = await goodsService.UpdateAsync(model);

            if (!flag)
            {
                return(Json(new AjaxResult {
                    Status = 0, Msg = "商品编辑失败"
                }));
            }
            return(Json(new AjaxResult {
                Status = 1, Msg = "商品编辑成功"
            }));
        }
Ejemplo n.º 2
0
        public async Task <long> AddAsync(GoodsAddEditModel goods)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                GoodsEntity entity = new GoodsEntity();
                entity.Code              = CommonHelper.GetRandom2();
                entity.Description       = goods.Description;
                entity.GoodsAreaId       = goods.GoodsAreaId;
                entity.GoodsSecondTypeId = goods.GoodsSecondTypeId.Value;
                entity.GoodsTypeId       = goods.GoodsTypeId;
                entity.Inventory         = goods.Inventory;
                entity.IsPutaway         = goods.IsPutaway;
                entity.IsRecommend       = goods.IsRecommend;
                entity.Name              = goods.Name;
                entity.Price             = goods.Price;
                entity.RealityPrice      = goods.RealityPrice;
                entity.Standard          = "件";
                dbc.Goods.Add(entity);
                await dbc.SaveChangesAsync();

                BonusRatioEntity bonusRatio = new BonusRatioEntity();
                bonusRatio.GoodsId = entity.Id;
                dbc.BonusRatios.Add(bonusRatio);
                await dbc.SaveChangesAsync();

                return(entity.Id);
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Add(GoodsAddEditModel model)
        {
            if (string.IsNullOrEmpty(model.Description))
            {
                model.Description = "";
            }
            if (model.Inventory < 0)
            {
                return(Json(new AjaxResult {
                    Status = 0, Msg = "库存不能小于零"
                }));
            }
            if (model.GoodsSecondTypeId == null)
            {
                model.GoodsSecondTypeId = await goodsSecondTypeService.GetIdByNameAsync("空类型");
            }
            long id = await goodsService.AddAsync(model);

            if (id <= 0)
            {
                return(Json(new AjaxResult {
                    Status = 0, Msg = "商品添加失败"
                }));
            }
            return(Json(new AjaxResult {
                Status = 1, Msg = "商品添加成功"
            }));
        }
Ejemplo n.º 4
0
        public async Task <bool> UpdateAsync(GoodsAddEditModel goods)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                GoodsEntity entity = await dbc.GetAll <GoodsEntity>().SingleOrDefaultAsync(g => g.Id == goods.Id);

                if (entity == null)
                {
                    return(false);
                }
                entity.Description       = goods.Description;
                entity.GoodsAreaId       = goods.GoodsAreaId;
                entity.GoodsSecondTypeId = goods.GoodsSecondTypeId.Value;
                entity.GoodsTypeId       = goods.GoodsTypeId;
                entity.Inventory         = goods.Inventory;
                entity.IsPutaway         = goods.IsPutaway;
                entity.IsRecommend       = goods.IsRecommend;
                entity.Name         = goods.Name;
                entity.Price        = goods.Price;
                entity.RealityPrice = goods.RealityPrice;
                await dbc.SaveChangesAsync();

                return(true);
            }
        }