예제 #1
0
        public object SaveStoreWeightUserGameInfo(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg     = string.Empty;
                string storeId    = dicParas.ContainsKey("storeId") ? (dicParas["storeId"] + "") : string.Empty;
                string userId     = dicParas.ContainsKey("userId") ? (dicParas["userId"] + "") : string.Empty;
                string weightType = dicParas.ContainsKey("weightType") ? (dicParas["weightType"] + "") : string.Empty;
                var    gameIDs    = dicParas.ContainsKey("gameIDs") ? ((object[])dicParas["gameIDs"]).Cast <int>() : null;

                #region 验证参数
                if (string.IsNullOrEmpty(storeId))
                {
                    errMsg = "门店ID不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrEmpty(userId))
                {
                    errMsg = "门店老板ID不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrEmpty(weightType))
                {
                    errMsg = "门店权重类别不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }
                #endregion

                //开启EF事务
                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {
                        IBase_StoreWeightService base_StoreWeightService = BLLContainer.Resolve <IBase_StoreWeightService>();
                        int iWeightType = Convert.ToInt32(weightType);
                        int iUserId     = Convert.ToInt32(userId);

                        if (!base_StoreWeightService.Any(a => a.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase) && a.BossID == iUserId))
                        {
                            errMsg = "请先分配权重";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        var base_StoreWeight = base_StoreWeightService.GetModels(p => p.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase) && p.BossID == iUserId).FirstOrDefault();
                        base_StoreWeight.WeightType = iWeightType;
                        if (!base_StoreWeightService.Update(base_StoreWeight))
                        {
                            errMsg = "保存权重用户游戏机信息失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        if (iWeightType == (int)ChainStoreWeightType.Game)
                        {
                            if (gameIDs == null)
                            {
                                errMsg = "选择的游戏机列表不能为空";
                                return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                            }

                            //先删除后添加
                            int iId                   = base_StoreWeight.ID;
                            var dbContext             = DbContextFactory.CreateByModelNamespace(typeof(Base_StoreWeight_Game).Namespace);
                            var base_StoreWeight_Game = dbContext.Set <Base_StoreWeight_Game>().Where(p => p.WeightID == iId).ToList();
                            foreach (var model in base_StoreWeight_Game)
                            {
                                dbContext.Entry(model).State = EntityState.Deleted;
                            }

                            foreach (var gId in gameIDs)
                            {
                                var base_StoreWeight_GameModel = new Base_StoreWeight_Game();
                                base_StoreWeight_GameModel.WeightID = iId;
                                base_StoreWeight_GameModel.GameID   = gId;
                                dbContext.Entry(base_StoreWeight_GameModel).State = EntityState.Added;
                            }

                            if (dbContext.SaveChanges() < 0)
                            {
                                errMsg = "保存权重用户游戏机信息失败";
                                return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                            }
                        }

                        ts.Complete();
                    }
                    catch (Exception ex)
                    {
                        errMsg = ex.Message;
                        return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                    }
                }

                return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn));
            }
            catch (Exception e)
            {
                return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message));
            }
        }
예제 #2
0
        public object AddStoreWeight(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg      = string.Empty;
                string storeId     = dicParas.ContainsKey("storeId") ? (dicParas["storeId"] + "") : string.Empty;
                string userId      = dicParas.ContainsKey("userId") ? (dicParas["userId"] + "") : string.Empty;
                string weightValue = dicParas.ContainsKey("weightValue") ? (dicParas["weightValue"] + "") : string.Empty;

                #region 验证参数
                if (string.IsNullOrEmpty(storeId))
                {
                    errMsg = "门店ID不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrEmpty(userId))
                {
                    errMsg = "门店老板ID不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrEmpty(weightValue))
                {
                    errMsg = "门店权重值不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!Utils.isNumber(weightValue))
                {
                    errMsg = "门店权重值格式不正确";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }
                #endregion

                IBase_StoreWeightService base_StoreWeightService = BLLContainer.Resolve <IBase_StoreWeightService>();
                int bossId = Convert.ToInt32(userId);
                if (base_StoreWeightService.Any(a => a.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase) && a.BossID == bossId))
                {
                    errMsg = "该门店老板权重已分配";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                int iWeightValue   = Convert.ToInt32(weightValue);
                int sumWeightValue = base_StoreWeightService.GetModels(p => p.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase)).Sum(s => s.WeightValue) ?? 0;
                if ((sumWeightValue + iWeightValue) > 100)
                {
                    errMsg = "门店权重之和不得超过100";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                var base_StoreWeight = new Base_StoreWeight();
                base_StoreWeight.BossID      = bossId;
                base_StoreWeight.StoreID     = storeId;
                base_StoreWeight.WeightType  = (int)ChainStoreWeightType.Whole;
                base_StoreWeight.WeightValue = iWeightValue;
                if (!base_StoreWeightService.Add(base_StoreWeight))
                {
                    errMsg = "添加门店权重信息失败";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn));
            }
            catch (Exception e)
            {
                return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message));
            }
        }