/// <summary> /// 添加喷漆打折配置 /// </summary> /// <param name="conn"></param> /// <param name="model"></param> /// <returns></returns> public static int AddPaintDiscountConfig(SqlConnection conn, PaintDiscountConfigModel model) { #region SQL var sql = @"INSERT INTO Configuration..PaintDiscountConfig ( PackageId , ServicePid , SurfaceCount , ActivityPrice , ActivityName , ActivityExplain , ActivityImage ) OUTPUT inserted.PKID VALUES ( @PackageId , @ServicePid , @SurfaceCount , @ActivityPrice , @ActivityName , @ActivityExplain , @ActivityImage );"; #endregion var parameters = new[] { new SqlParameter("@PackageId", model.PackageId), new SqlParameter("@ServicePid", model.ServicePid), new SqlParameter("@SurfaceCount", model.SurfaceCount), new SqlParameter("@ActivityPrice", model.ActivityPrice), new SqlParameter("@ActivityName", model.ActivityName ?? string.Empty), new SqlParameter("@ActivityExplain", model.ActivityExplain ?? string.Empty), new SqlParameter("@ActivityImage", model.ActivityImage ?? string.Empty) }; return(Convert.ToInt32(SqlHelper.ExecuteScalar(conn, CommandType.Text, sql, parameters))); }
/// <summary> /// 添加喷漆打折配置 /// </summary> /// <param name="conn"></param> /// <param name="model"></param> /// <returns></returns> public static int AddPaintDiscountConfig(SqlConnection conn, PaintDiscountConfigModel model) { #region SQL var sql = @"INSERT INTO Configuration..PaintDiscountConfig ( ServicePid , SurfaceCount , ActivityPrice , ActivityName , ActivityExplain , ActivityImage ) VALUES ( @ServicePid , @SurfaceCount , @ActivityPrice , @ActivityName , @ActivityExplain , @ActivityImage ) SELECT SCOPE_IDENTITY();"; #endregion var parameters = new[] { new SqlParameter("@ServicePid", model.ServicePid), new SqlParameter("@SurfaceCount", model.SurfaceCount), new SqlParameter("@ActivityPrice", model.ActivityPrice), new SqlParameter("@ActivityName", model.ActivityName ?? string.Empty), new SqlParameter("@ActivityExplain", model.ActivityExplain ?? string.Empty), new SqlParameter("@ActivityImage", model.ActivityImage ?? string.Empty) }; return(Convert.ToInt32(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, parameters))); }
/// <summary> /// 更新喷漆打折配置 /// </summary> /// <param name="model"></param> /// <returns></returns> public ActionResult UpdatePaintConfig(PaintDiscountConfigModel model) { if (model == null || string.IsNullOrWhiteSpace(model.ServicePid) || model.SurfaceCount < 1) { return(Json(new { Status = false, Msg = "未知的编辑对象" }, JsonRequestBehavior.AllowGet)); } if (!(model.ActivityPrice > 0)) { return(Json(new { Status = false, Msg = "活动价格须大于0" }, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrWhiteSpace(model.ActivityName)) { return(Json(new { Status = false, Msg = "权益名称不能为空" }, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrWhiteSpace(model.ActivityImage)) { return(Json(new { Status = false, Msg = "活动图片不能为空" }, JsonRequestBehavior.AllowGet)); } var manager = new PaintDiscountConfigManager(); var isExist = manager.IsExistPaintDiscountConfig(model); if (isExist) { return(Json(new { Status = false, Msg = "已存在重复的数据,不能重复编辑" }, JsonRequestBehavior.AllowGet)); } var user = User.Identity.Name; var result = manager.UpdatePaintDiscountConfig(model, user); return(Json(new { Status = result, Msg = $"编辑{(result ? "成功" : "失败")}" }, JsonRequestBehavior.AllowGet)); }
public ActionResult DeletePaintConfig(PaintDiscountConfigModel model) { if (string.IsNullOrWhiteSpace(model.ServicePid) || model.SurfaceCount < 1) { return(Json(new { Status = false, Msg = "未知的删除对象" }, JsonRequestBehavior.AllowGet)); } var manager = new PaintDiscountConfigManager(); var user = User.Identity.Name; var result = manager.DeletePaintDiscountConfig(model.PackageId, model.ServicePid, model.SurfaceCount, user); return(Json(new { Status = result, Msg = $"删除{(result ? "成功" : "失败")}" }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 判断喷漆打折配置唯一性 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool IsExistPaintDiscountConfig(PaintDiscountConfigModel model) { var result = true; try { result = dbScopeManagerConfigurationRead.Execute (conn => DalPaintDiscountConfig.IsExistPaintDiscountConfig(conn, model)); } catch (Exception ex) { Logger.Error("IsExistPaintDiscountConfig", ex); } return(result); }
/// <summary> /// 判断喷漆打折配置是否重复 /// </summary> /// <param name="conn"></param> /// <param name="model"></param> /// <returns></returns> public static bool IsExistPaintDiscountConfig (SqlConnection conn, PaintDiscountConfigModel model) { #region Sql var sql = @"SELECT COUNT(1) FROM Configuration..PaintDiscountConfig AS s WITH ( NOLOCK ) WHERE s.ServicePid = @ServicePid AND s.SurfaceCount = @SurfaceCount AND s.IsDeleted=0 AND s.PKID <> @PKID;"; #endregion var parameters = new[] { new SqlParameter("@ServicePid", model.ServicePid), new SqlParameter("@SurfaceCount", model.SurfaceCount), new SqlParameter("@PKID", model.PKID) }; var count = Convert.ToInt32(SqlHelper.ExecuteScalar(conn, CommandType.Text, sql, parameters)); return(count > 0); }
/// <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); }
/// <summary> /// 更新喷漆打折配置 /// </summary> /// <param name="conn"></param> /// <param name="model"></param> /// <returns></returns> public static bool UpdatePaintDiscountConfig(SqlConnection conn, PaintDiscountConfigModel model) { #region Sql var sql = @"UPDATE Configuration..PaintDiscountConfig SET SurfaceCount = @SurfaceCount , ActivityPrice = @ActivityPrice , ActivityName = @ActivityName , ActivityExplain = @ActivityExplain , ActivityImage = @ActivityImage , IsDeleted = 0 , LastUpdateDateTime = GETDATE() WHERE PKID = @PKID;"; #endregion var parameters = new[] { new SqlParameter("@SurfaceCount", model.SurfaceCount), new SqlParameter("@ActivityPrice", model.ActivityPrice), new SqlParameter("@ActivityName", model.ActivityName ?? string.Empty), new SqlParameter("@ActivityExplain", model.ActivityExplain ?? string.Empty), new SqlParameter("@ActivityImage", model.ActivityImage ?? string.Empty), new SqlParameter("@PKID", model.PKID) }; return(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, parameters) > 0); }