/// <summary> /// 更新banner /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool UpdateCarProductsBanner(CarProductsBanner model) { using (var conn = new SqlConnection(StrConn)) { const string sql = @"UPDATE CarProductsBanner SET FKFloorID = @FKFloorID, Name = @Name, ImgUrl = @ImgUrl, StartTime = @StartTime, EndTime = @EndTime, IsEnabled = @IsEnabled, Sort = @Sort, LinkType = @LinkType, Link = @Link, Type = @Type, UpdateTime = GETDATE() WHERE PKID = @PKID;"; var sqlPrams = new[] { new SqlParameter("@FKFloorID", model.FKFloorID), new SqlParameter("@Name", model.Name), new SqlParameter("@ImgUrl", model.ImgUrl), new SqlParameter("@StartTime", model.StartTime), new SqlParameter("@EndTime", model.EndTime), new SqlParameter("@IsEnabled", model.IsEnabled), new SqlParameter("@Sort", model.Sort), new SqlParameter("@LinkType", model.LinkType), new SqlParameter("@Link", model.Link), new SqlParameter("@Type", model.Type), new SqlParameter("@PKID", model.PKID) }; return(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, sqlPrams) > 0); } }
/// <summary> /// 更新banner图片 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool UpdateCarProductsBanner(CarProductsBanner model) { try { return(DALCarProducts.UpdateCarProductsBanner(model)); } catch (Exception ex) { logger.Error("UpdateCarProductsBanner", ex); } return(false); }
/// <summary> /// 插入banner图片 /// </summary> /// <param name="model"></param> /// <returns></returns> public int InsertCarProductsBanner(CarProductsBanner model) { try { return(DALCarProducts.InsertCarProductsBanner(model)); } catch (Exception ex) { logger.Error("InsertCarProductsBanner", ex); } return(0); }
/// <summary> /// 查询相同类型banner数量 /// </summary> /// <param name="model"></param> /// <returns></returns> public int SelectCarProductsBannerCount(CarProductsBanner model) { var result = 0; try { result = DALCarProducts.SelectCarProductsBannerCount(model); } catch (Exception ex) { logger.Error("SelectCarProductsBannerCount", ex); } return(result); }
/// <summary> /// 是否存在相同排序 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool IsExistEqualSort(CarProductsBanner model) { var result = true; try { result = DALCarProducts.IsExistEqualSort(model); } catch (Exception ex) { logger.Error("IsExistEqualSort", ex); } return(result); }
/// <summary> /// 添加banner /// </summary> /// <param name="model"></param> /// <returns></returns> public static int InsertCarProductsBanner(CarProductsBanner model) { using (var conn = new SqlConnection(StrConn)) { const string sql = @"INSERT INTO Configuration.dbo.CarProductsBanner ( FKFloorID , Name , ImgUrl , StartTime , EndTime , IsEnabled , Sort , LinkType , Link , Type ) VALUES ( @FKFloorID , @Name , @ImgUrl , @StartTime , @EndTime , @IsEnabled , @Sort , @LinkType , @Link , @Type ); SELECT ISNULL(@@IDENTITY,0)"; var sqlPrams = new[] { new SqlParameter("@FKFloorID", model.FKFloorID), new SqlParameter("@Name", model.Name), new SqlParameter("@ImgUrl", model.ImgUrl), new SqlParameter("@StartTime", model.StartTime), new SqlParameter("@EndTime", model.EndTime), new SqlParameter("@IsEnabled", model.IsEnabled), new SqlParameter("@Sort", model.Sort), new SqlParameter("@LinkType", model.LinkType), new SqlParameter("@Link", model.Link), new SqlParameter("@Type", model.Type) }; return(Convert.ToInt32(SqlHelper.ExecuteScalar(conn, CommandType.Text, sql, sqlPrams))); } }
/// <summary> /// 查询相同类型banner数量 /// </summary> /// <param name="model"></param> /// <returns></returns> public static int SelectCarProductsBannerCount(CarProductsBanner model) { using (var conn = new SqlConnection(StrConn)) { var sql = @"SELECT COUNT(0) FROM Configuration..CarProductsBanner WHERE Type = @Type AND IsEnabled = 1 AND ( StartTime IS NULL OR EndTime IS NULL OR StartTime < GETDATE() AND EndTime > GETDATE() )"; sql += (model.PKID.HasValue && model.PKID.Value > 0) ? $" AND PKID != {model.PKID.Value}" : ""; var parameters = new SqlParameter[] { new SqlParameter("@Type", model.Type) }; var count = SqlHelper.ExecuteScalar(conn, CommandType.Text, sql, parameters); return(Convert.ToInt32(count)); } }
/// <summary> /// 保存banner /// </summary> /// <param name="model"></param> /// <returns></returns> public ActionResult SaveBanner(CarProductsBanner model) { // 车品坑位 启用中的不能存在相同顺序 if ((model.Type == 1 || model.Type == 2) && model.IsEnabled == true) { if (_manager.IsExistEqualSort(model)) { return(Json(new { Success = false, Msg = "系统已经存在此排序,请勿重复添加" })); } } // 车品坑位 启用中的不能大于10个 if (model.Type == 2 && model.IsEnabled == true) { if (_manager.SelectCarProductsBannerCount(model) >= 10) { return(Json(new { Success = false, Msg = "已经存在10个启用数据,请勿重复添加" })); } } // 弹层 启用中的只能有一个 if (model.Type == 8 && model.IsEnabled == true) { if (_manager.SelectCarProductsBannerCount(model) >= 1) { return(Json(new { Success = false, Msg = "只能存在一条启用状态的弹层,请勿重复添加" })); } } if (model.PKID <= 0) { var result = _manager.InsertCarProductsBanner(model); using (var client = new ConfigLogClient()) { client.InsertDefaultLogQueue("CommonConfigLog", JsonConvert.SerializeObject(new { ObjectId = (int?)result, ObjectType = "CarProductsBanner", BeforeValue = "", AfterValue = JsonConvert.SerializeObject(model), Remark = "新建", Creator = User.Identity.Name, })); } return(Json(new { Success = result > 0 })); } else { var beforeModel = _manager.GetCarProductsBannerEntity(model.PKID ?? 0); var result = _manager.UpdateCarProductsBanner(model); if (result) { using (var client = new ConfigLogClient()) { client.InsertDefaultLogQueue("CommonConfigLog", JsonConvert.SerializeObject(new { ObjectId = model.PKID, ObjectType = "CarProductsBanner", BeforeValue = JsonConvert.SerializeObject(beforeModel), AfterValue = JsonConvert.SerializeObject(model), Remark = "更新", Creator = User.Identity.Name, })); } } return(Json(new { Success = result })); } }