Esempio n. 1
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);
            }
        }
        public async Task <BonusRatio> GetModelAsync(long goodsId)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                BonusRatioEntity entity = await dbc.GetAll <BonusRatioEntity>().SingleOrDefaultAsync(b => b.GoodsId == goodsId);

                if (entity == null)
                {
                    return(null);
                }
                return(new BonusRatio
                {
                    CommonOne = entity.CommonOne,
                    CommonThree = entity.CommonThree,
                    CommonTwo = entity.CommonTwo,
                    GoldOne = entity.GoldOne,
                    GoldThree = entity.GoldThree,
                    GoldTwo = entity.GoldTwo,
                    GoodsId = entity.GoodsId,
                    PlatinumOne = entity.PlatinumOne,
                    PlatinumThree = entity.PlatinumThree,
                    PlatinumTwo = entity.PlatinumTwo
                });
            }
        }
        public async Task <bool> UpdateAsync(BonusRatio bonusRatio)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                BonusRatioEntity entity = await dbc.GetAll <BonusRatioEntity>().SingleOrDefaultAsync(b => b.GoodsId == bonusRatio.GoodsId);

                if (entity == null)
                {
                    entity               = new BonusRatioEntity();
                    entity.CommonOne     = bonusRatio.CommonOne;
                    entity.CommonThree   = bonusRatio.CommonThree;
                    entity.CommonTwo     = bonusRatio.CommonTwo;
                    entity.GoldOne       = bonusRatio.GoldOne;
                    entity.GoldThree     = bonusRatio.GoldThree;
                    entity.GoldTwo       = bonusRatio.GoldTwo;
                    entity.GoodsId       = bonusRatio.GoodsId;
                    entity.PlatinumOne   = bonusRatio.PlatinumOne;
                    entity.PlatinumThree = bonusRatio.PlatinumThree;
                    entity.PlatinumTwo   = bonusRatio.PlatinumTwo;
                    dbc.BonusRatios.Add(entity);
                }
                else
                {
                    entity.CommonOne     = bonusRatio.CommonOne;
                    entity.CommonThree   = bonusRatio.CommonThree;
                    entity.CommonTwo     = bonusRatio.CommonTwo;
                    entity.GoldOne       = bonusRatio.GoldOne;
                    entity.GoldThree     = bonusRatio.GoldThree;
                    entity.GoldTwo       = bonusRatio.GoldTwo;
                    entity.GoodsId       = bonusRatio.GoodsId;
                    entity.PlatinumOne   = bonusRatio.PlatinumOne;
                    entity.PlatinumThree = bonusRatio.PlatinumThree;
                    entity.PlatinumTwo   = bonusRatio.PlatinumTwo;
                }
                await dbc.SaveChangesAsync();

                return(true);
            }
        }