Exemple #1
0
        /// <summary>
        /// 删除保养项目加价配置 --只做逻辑删除
        /// </summary>
        /// <param name="pkid"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool DeleteBaoYangInstallFeeConfig(string serviceId, string user)
        {
            var result = true;

            try
            {
                var logs      = new List <BaoYangOprLog>();
                var configs   = dbScopeManagerGungnirRead.Execute(conn => DalBaoYangInstallFeeConfig.SelectBaoYangInstallFeeConfig(conn, serviceId));
                var oldValues = configs.Where(s => s.PKID > 0).ToList();
                if (oldValues != null && oldValues.Any())
                {
                    dbScopeManagerGungnir.CreateTransaction(conn =>
                    {
                        foreach (var oldValue in oldValues)
                        {
                            var isDel = DalBaoYangInstallFeeConfig.DeleteBaoYangInstallFeeConfigByPKID(conn, oldValue.PKID);
                            if (!isDel)
                            {
                                throw new Exception($"DeleteBaoYangInstallFeeConfigByPKID失败,待删除数据{JsonConvert.SerializeObject(oldValue)}");
                            }
                            var log = new BaoYangOprLog
                            {
                                LogType     = "BaoYangInstallFeeConfig",
                                IdentityID  = oldValue.PKID.ToString(),
                                OldValue    = JsonConvert.SerializeObject(oldValues),
                                NewValue    = null,
                                Remarks     = $"删除保养项目:{oldValue.ServiceName}的加价配置",
                                OperateUser = user,
                            };
                            logs.Add(log);
                        }
                    });
                    foreach (var log in logs)
                    {
                        LoggerManager.InsertLog("BYOprLog", log);
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
                Logger.Error("DeleteBaoYangInstallFeeConfig", ex);
            }
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// 查询保养项目加价配置
        /// </summary>
        /// <param name="serviceId"></param>
        /// <returns></returns>
        public Dictionary <string, List <BaoYangInstallFeeConfigModel> > SelectBaoYangInstallFeeConfig(string serviceId)
        {
            var result = null as Dictionary <string, List <BaoYangInstallFeeConfigModel> >;

            try
            {
                var configs = dbScopeManagerGungnirRead.Execute(conn =>
                                                                DalBaoYangInstallFeeConfig.SelectBaoYangInstallFeeConfig(conn, serviceId));
                if (configs != null && configs.Any())
                {
                    var configGroup = configs.GroupBy(g => g.ServiceName).ToDictionary(s => s.Key, s => s.ToList());
                    if (configGroup != null)
                    {
                        result = configGroup;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("SelectBaoYangInstallFeeConfig", ex);
            }
            return(result);
        }
Exemple #3
0
        /// <summary>
        /// 添加或编辑保养项目加价配置
        /// </summary>
        /// <param name="models"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool AddOrEditBaoYangInstallFeeConfig(List <BaoYangInstallFeeConfigModel> models, string user)
        {
            var result = false;

            try
            {
                var delList     = new List <BaoYangInstallFeeConfigModel>();
                var logs        = new List <BaoYangOprLog>();
                var serviceId   = models.Select(s => s.ServiceId).FirstOrDefault();
                var configs     = dbScopeManagerGungnirRead.Execute(conn => DalBaoYangInstallFeeConfig.SelectBaoYangInstallFeeConfig(conn, serviceId));
                var existConfig = configs.Where(s => s.PKID > 0).ToList();
                foreach (var oldValue in existConfig)
                {
                    var sameValue = models.Where(model =>
                                                 (string.Equals(model.ServiceId, oldValue.ServiceId) && model.CarMinPrice.Equals(oldValue.CarMinPrice) &&
                                                  model.CarMaxPrice.Equals(oldValue.CarMaxPrice) && model.AddInstallFee.Equals(oldValue.AddInstallFee))).FirstOrDefault();
                    if (sameValue == null)
                    {
                        delList.Add(oldValue);//删除旧数据
                    }
                    else
                    {
                        models.Remove(sameValue);//数据没变的不做任何操作
                    }
                }
                dbScopeManagerGungnir.CreateTransaction(conn =>
                {
                    #region  除旧数据
                    foreach (var oldValue in delList)
                    {
                        var log = new BaoYangOprLog
                        {
                            LogType     = "BaoYangInstallFeeConfig",
                            IdentityID  = oldValue.PKID.ToString(),
                            OldValue    = JsonConvert.SerializeObject(oldValue),
                            NewValue    = null,
                            Remarks     = $"删除保养项目:{oldValue.ServiceName}的加价配置",
                            OperateUser = user,
                        };
                        logs.Add(log);
                        DalBaoYangInstallFeeConfig.DeleteBaoYangInstallFeeConfigByPKID(conn, oldValue.PKID);
                    }
                    #endregion

                    #region 插入新数据
                    foreach (var model in models)
                    {
                        var deletedModel = dbScopeManagerGungnirRead.Execute(co => DalBaoYangInstallFeeConfig.GetDeletedBaoYangInstallFeeConfig(co, model));
                        if (deletedModel != null)
                        {
                            var backUpResult = DalBaoYangInstallFeeConfig.BackUpBaoYangInstallFeeConfigByPKID(conn, deletedModel.PKID);
                            if (!backUpResult)
                            {
                                throw new Exception($"BackUpBaoYangInstallFeeConfigByPKID失败,待插入数据{JsonConvert.SerializeObject(deletedModel)}");
                            }
                            var log = new BaoYangOprLog
                            {
                                LogType     = "BaoYangInstallFeeConfig",
                                IdentityID  = deletedModel.PKID.ToString(),
                                OldValue    = null,
                                NewValue    = JsonConvert.SerializeObject(deletedModel),
                                Remarks     = $"添加保养项目:{model.ServiceName}的加价配置",
                                OperateUser = user,
                            };
                            logs.Add(log);
                        }
                        else
                        {
                            var pkid = DalBaoYangInstallFeeConfig.AddBaoYangInstallFeeConfig(conn, model);
                            if (pkid < 1)
                            {
                                throw new Exception($"AddBaoYangInstallFeeConfig失败,待插入数据{JsonConvert.SerializeObject(model)}");
                            }
                            model.PKID               = pkid;
                            model.CreateDateTime     = DateTime.Now;
                            model.LastUpdateDateTime = DateTime.Now;
                            var log = new BaoYangOprLog
                            {
                                LogType     = "BaoYangInstallFeeConfig",
                                IdentityID  = model.PKID.ToString(),
                                OldValue    = null,
                                NewValue    = JsonConvert.SerializeObject(model),
                                Remarks     = $"添加保养项目:{model.ServiceName}的加价配置",
                                OperateUser = user,
                            };
                            logs.Add(log);
                        }
                    }
                    #endregion
                    result = true;
                });
                foreach (var log in logs)
                {
                    LoggerManager.InsertLog("BYOprLog", log);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("AddOrEditBaoYangInstallFeeConfig", ex);
            }
            return(result);
        }