예제 #1
0
        public async Task <ActionResult> Bonusset(BonusRatio bonusRatio)
        {
            Type    type  = typeof(BonusRatio);
            var     props = type.GetProperties();
            decimal val;

            foreach (var prop in props)
            {
                if (!decimal.TryParse(prop.GetValue(bonusRatio).ToString(), out val))
                {
                    return(Json(new AjaxResult {
                        Status = 1, Msg = "佣金设置参数错误"
                    }));
                }
                if (val <= 0)
                {
                    return(Json(new AjaxResult {
                        Status = 1, Msg = "佣金设置参数必须大于零"
                    }));
                }
            }
            bool flag = await bonusRatioService.UpdateAsync(bonusRatio);

            return(Json(new AjaxResult {
                Status = 1, Msg = "佣金设置成功"
            }));
        }
예제 #2
0
        public async Task <ActionResult> GetBonusRatio(long id)
        {
            BonusRatio res = await bonusRatioService.GetModelAsync(id);

            if (res == null)
            {
                res = new BonusRatio();
            }
            return(Json(new AjaxResult {
                Status = 1, Data = new { BonusRatio = res }
            }));
        }
예제 #3
0
        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);
            }
        }