Exemplo n.º 1
0
        public object DelStoreWeight(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg = string.Empty;
                string id     = dicParas.ContainsKey("id") ? (dicParas["id"] + "") : string.Empty;

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

                //开启EF事务
                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {
                        IBase_StoreWeightService base_StoreWeightService = BLLContainer.Resolve <IBase_StoreWeightService>();
                        int iId = Convert.ToInt32(id);
                        var base_StoreWeight = base_StoreWeightService.GetModels(p => p.ID == iId).FirstOrDefault();
                        if (!base_StoreWeightService.Delete(base_StoreWeight))
                        {
                            errMsg = "删除门店权重信息失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        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;
                        }

                        if (dbContext.SaveChanges() < 0)
                        {
                            errMsg = "删除门店权重游戏机信息失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        ts.Complete();
                    }
                    catch (Exception ex)
                    {
                        return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, ex.Message));
                    }
                }

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