/// <summary> /// 添加喷漆打折配置 /// </summary> /// <param name="model"></param> /// <param name="user"></param> /// <returns></returns> public bool AddPaintDiscountConfig(PaintDiscountConfigModel model, string user) { var result = false; try { var oldValue = GetPaintDiscountConfig(model.ServicePid, model.SurfaceCount); if (oldValue == null) { var pkid = dbScopeManagerConfiguration.Execute (conn => DalPaintDiscountConfig.AddPaintDiscountConfig(conn, model)); result = pkid > 0; model.PKID = pkid; } else if (oldValue.IsDeleted) { model.PKID = oldValue.PKID; result = dbScopeManagerConfiguration.Execute (conn => DalPaintDiscountConfig.UpdatePaintDiscountConfig(conn, model)); } model.CreateDateTime = DateTime.Now; model.LastUpdateDateTime = DateTime.Now; var log = new PaintDiscountOprLogModel { LogType = "PaintDiscountConfig", IdentityId = $"{model.ServicePid}_{model.SurfaceCount}", OperationType = "Add", OldValue = null, NewValue = JsonConvert.SerializeObject(model), Remarks = $"添加服务Pid:{model.ServicePid},面数:{model.SurfaceCount}的配置", Operator = user, }; LoggerManager.InsertLog("PaintDiscountOprLog", log); } catch (Exception ex) { result = false; Logger.Error("AddPaintDiscountConfig", ex); } return(result); }
/// <summary> /// 更新喷漆打折配置 /// </summary> /// <param name="model"></param> /// <param name="user"></param> /// <returns></returns> public bool UpdatePaintDiscountConfig (PaintDiscountConfigModel model, string user) { var result = false; try { var oldValue = GetPaintDiscountConfig(model.ServicePid, model.SurfaceCount); if (oldValue != null) { model.PKID = oldValue.PKID; result = dbScopeManagerConfiguration.Execute(conn => DalPaintDiscountConfig.UpdatePaintDiscountConfig(conn, model)); if (!result) { throw new Exception($"UpdatePaintDiscountConfig失败,待更新数据{JsonConvert.SerializeObject(model)}"); } model.CreateDateTime = oldValue.CreateDateTime; model.LastUpdateDateTime = DateTime.Now; var log = new PaintDiscountOprLogModel { LogType = "PaintDiscountConfig", IdentityId = $"{model.ServicePid}_{model.SurfaceCount}", OperationType = "Update", OldValue = JsonConvert.SerializeObject(oldValue), NewValue = JsonConvert.SerializeObject(model), Remarks = $"更新服务Pid:{model.ServicePid},面数:{model.SurfaceCount}的配置", Operator = user, }; LoggerManager.InsertLog("PaintDiscountOprLog", log); } } catch (Exception ex) { result = false; Logger.Error("UpdatePaintDiscountConfig", ex); } return(result); }