Пример #1
0
        /// <summary>
        /// 获取该省份下的城市--下拉框选项
        /// </summary>
        /// <param name="provinceId"></param>
        /// <returns></returns>
        public List <PeccancyRegionMiniModel> GetPeccancyCitiesByProvinceId(int provinceId)
        {
            List <PeccancyRegionMiniModel> result = null;

            try
            {
                var configs = DalPeccancyQueryConfig.GetPeccancyCitiesByProvinceId(provinceId);
                result = configs?.Select(s => new PeccancyRegionMiniModel {
                    RegionId = s.CityId, RegionName = s.CityName
                }).ToList();
            }
            catch (Exception ex)
            {
                Logger.Error("GetPeccancyCitiesByProvinceId", ex);
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 删除违章查询省份配置
        /// </summary>
        /// <param name="provinceId"></param>
        /// <returns></returns>
        public bool DeletePeccancyProvinceConfig(int provinceId, string user)
        {
            var result = false;

            try
            {
                using (var dbhelper = new Tuhu.Component.Common.SqlDbHelper(grconnectionString))
                {
                    var oldValue = DalPeccancyQueryConfig.GetPeccancyProvinceConfigByProvinceId(provinceId);
                    if (oldValue != null)
                    {
                        var cityConfigs = DalPeccancyQueryConfig.GetPeccancyCitiesByProvinceId(provinceId);
                        if (cityConfigs != null && cityConfigs.Any())
                        {
                            dbhelper.BeginTransaction();
                            var deleteProvince = DalPeccancyQueryConfig.DeletePeccancyCityConfigByProvinceId(dbhelper, provinceId);
                            var deleteCity     = DalPeccancyQueryConfig.DeletePeccancyProvinceConfig(dbhelper, provinceId);//同时删除该省份下的所有城市配置
                            if (deleteProvince && deleteCity)
                            {
                                dbhelper.Commit();
                                result = true;
                                #region  除的省份和城市记录日志
                                var logs        = new List <PeccancyConfigOprLogModel>();
                                var provinceLog = new PeccancyConfigOprLogModel
                                {
                                    LogType       = "PeccancyProvinceConfig",
                                    IdentityId    = $"{oldValue.ProvinceId}",
                                    OperationType = "Delete",
                                    OldValue      = JsonConvert.SerializeObject(oldValue),
                                    NewValue      = null,
                                    Remarks       = $"删除 违章查询省份:{oldValue.ProvinceName} 的配置",
                                    Operator      = user,
                                };
                                logs.Add(provinceLog);
                                foreach (var city in cityConfigs)
                                {
                                    var cityLog = new PeccancyConfigOprLogModel
                                    {
                                        LogType       = "PeccancyCityConfig",
                                        IdentityId    = $"{city.CityId}",
                                        OperationType = "Delete",
                                        OldValue      = JsonConvert.SerializeObject(city),
                                        NewValue      = null,
                                        Remarks       = $"删除 违章查询城市:{city.CityName} 的配置",
                                        Operator      = user,
                                    };
                                    logs.Add(cityLog);
                                }
                                if (logs.Any())
                                {
                                    logs.ForEach(s => LoggerManager.InsertLog("PeccancyConfigOprLog", s));
                                }
                                #endregion
                            }
                        }
                        else
                        {
                            result = DalPeccancyQueryConfig.DeletePeccancyProvinceConfig(dbhelper, provinceId);
                            if (result)
                            {
                                var log = new PeccancyConfigOprLogModel
                                {
                                    LogType       = "PeccancyProvinceConfig",
                                    IdentityId    = $"{oldValue.ProvinceId}",
                                    OperationType = "Delete",
                                    OldValue      = JsonConvert.SerializeObject(oldValue),
                                    NewValue      = null,
                                    Remarks       = $"删除 违章查询省份:{oldValue.ProvinceName} 的配置",
                                    Operator      = user,
                                };
                                LoggerManager.InsertLog("PeccancyConfigOprLog", log);
                            }
                        }
                    }
                    else
                    {
                        result = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("DeletePeccancyProvinceConfig", ex);
            }
            return(result);
        }