public ActionResult AddAttribute(AttributeModel model, int cateId = -1) { CategoryInfo categoryInfo = AdminCategories.GetCategoryById(cateId); if (categoryInfo == null) return PromptView("分类不存在"); if (AdminCategories.GetAttrIdByCateIdAndName(cateId, model.AttributName) > 0) ModelState.AddModelError("AttributName", "名称已经存在"); AttributeGroupInfo attributeGroupInfo = AdminCategories.GetAttributeGroupById(model.AttrGroupId); if (attributeGroupInfo == null || attributeGroupInfo.CateId != cateId) ModelState.AddModelError("AttrGroupId", "属性组不存在"); if (ModelState.IsValid) { AttributeInfo attributeInfo = new AttributeInfo(); attributeInfo.Name = model.AttributName; attributeInfo.CateId = cateId; attributeInfo.AttrGroupId = model.AttrGroupId; attributeInfo.ShowType = model.ShowType; attributeInfo.IsFilter = model.IsFilter; attributeInfo.DisplayOrder = model.DisplayOrder; AdminCategories.CreateAttribute(attributeInfo, attributeGroupInfo); AddAdminOperateLog("添加分类属性", "添加分类属性,属性为:" + model.AttributName); return PromptView("分类属性添加成功"); } ViewData["cateId"] = categoryInfo.CateId; ViewData["categoryName"] = categoryInfo.Name; ViewData["attributeGroupList"] = GetAttributeGroupSelectList(cateId); ViewData["referer"] = ShopUtils.GetAdminRefererCookie(); return View(model); }
/// <summary> /// 通过IDataReader创建AttributeInfo信息 /// </summary> public static AttributeInfo BuildAttributeFromReader(IDataReader reader) { AttributeInfo attributeInfo = new AttributeInfo(); attributeInfo.AttrId = TypeHelper.ObjectToInt(reader["attrid"]); attributeInfo.Name = reader["name"].ToString(); attributeInfo.AttrGroupId = TypeHelper.ObjectToInt(reader["attrgroupid"]); attributeInfo.CateId = TypeHelper.ObjectToInt(reader["cateid"]); attributeInfo.ShowType = TypeHelper.ObjectToInt(reader["showtype"]); attributeInfo.IsFilter = TypeHelper.ObjectToInt(reader["isfilter"]); attributeInfo.DisplayOrder = TypeHelper.ObjectToInt(reader["displayorder"]); return attributeInfo; }
/// <summary> /// 创建属性 /// </summary> /// <param name="attributeInfo">属性信息</param> /// <param name="attributeGroupInfo">属性组信息</param> public static void CreateAttribute(AttributeInfo attributeInfo, AttributeGroupInfo attributeGroupInfo) { BrnShop.Data.Categories.CreateAttribute(attributeInfo, attributeGroupInfo.AttrGroupId, attributeGroupInfo.Name, attributeGroupInfo.DisplayOrder); //BrnShop.Core.BSPCache.Remove(CacheKeys.SHOP_CATEGORY_FILTERAANDVLIST + attributeInfo.CateId); BrnShop.Core.BSPCache.Remove(CacheKeys.SHOP_CATEGORY_AANDVLISTJSONCACHE + attributeInfo.CateId); }
/// <summary> /// 更新属性 /// </summary> /// <param name="newAttributeInfo">新属性</param> /// <param name="oldAttributeInfo">原属性</param> public static void UpdateAttribute(AttributeInfo attributeInfo) { BrnShop.Data.Categories.UpdateAttribute(attributeInfo); BrnShop.Core.BSPCache.Remove(CacheKeys.SHOP_CATEGORY_FILTERAANDVLIST + attributeInfo.CateId); BrnShop.Core.BSPCache.Remove(CacheKeys.SHOP_CATEGORY_FILTERAANDVLIST + attributeInfo.CateId); BrnShop.Core.BSPCache.Remove(CacheKeys.SHOP_CATEGORY_AANDVLISTJSONCACHE + attributeInfo.CateId); }
/// <summary> /// 更新属性 /// </summary> /// <param name="newAttributeInfo">新属性</param> /// <param name="oldAttributeInfo">原属性</param> public static void UpdateAttribute(AttributeInfo attributeInfo) { BrnShop.Core.BSPData.RDBS.UpdateAttribute(attributeInfo); }
/// <summary> /// 创建属性 /// </summary> /// <param name="attributeInfo">属性信息</param> /// <param name="attrGroupId">属性组id</param> /// <param name="attrGroupName">属性组名称</param> /// <param name="attrGroupDisplayOrder">属性组排序</param> public static void CreateAttribute(AttributeInfo attributeInfo, int attrGroupId, string attrGroupName, int attrGroupDisplayOrder) { BrnShop.Core.BSPData.RDBS.CreateAttribute(attributeInfo, attrGroupId, attrGroupName, attrGroupDisplayOrder); }
/// <summary> /// 创建属性 /// </summary> /// <param name="attributeInfo">属性信息</param> /// <param name="attrGroupId">属性组id</param> /// <param name="attrGroupName">属性组名称</param> /// <param name="attrGroupDisplayOrder">属性组排序</param> public void CreateAttribute(AttributeInfo attributeInfo, int attrGroupId, string attrGroupName, int attrGroupDisplayOrder) { DbParameter[] parms = { GenerateInParam("@name", SqlDbType.NChar, 30, attributeInfo.Name), GenerateInParam("@cateid", SqlDbType.SmallInt,2,attributeInfo.CateId), GenerateInParam("@attrgroupid", SqlDbType.SmallInt,2,attributeInfo.AttrGroupId), GenerateInParam("@showtype", SqlDbType.TinyInt,1,attributeInfo.ShowType), GenerateInParam("@isfilter", SqlDbType.TinyInt,1,attributeInfo.IsFilter), GenerateInParam("@displayorder", SqlDbType.Int,4,attributeInfo.DisplayOrder) }; string commandText = string.Format("INSERT INTO [{0}attributes]([name],[cateid],[attrgroupid],[showtype],[isfilter],[displayorder]) VALUES(@name,@cateid,@attrgroupid,@showtype,@isfilter,@displayorder);SELECT SCOPE_IDENTITY();", RDBSHelper.RDBSTablePre); int attrId = TypeHelper.ObjectToInt(RDBSHelper.ExecuteScalar(CommandType.Text, commandText, parms)); if (attrId > 0) { commandText = string.Format("INSERT INTO [{0}attributevalues]([attrvalue],[isinput],[attrname],[attrdisplayorder],[attrshowtype],[attrvaluedisplayorder],[attrgroupid],[attrgroupname],[attrgroupdisplayorder],[attrid]) VALUES('手动输入',1,'{1}',{2},{3},0,{4},'{5}',{6},{7})", RDBSHelper.RDBSTablePre, attributeInfo.Name, attributeInfo.DisplayOrder, attributeInfo.ShowType, attrGroupId, attrGroupName, attrGroupDisplayOrder, attrId); RDBSHelper.ExecuteNonQuery(CommandType.Text, commandText); } }
/// <summary> /// 更新属性 /// </summary> /// <param name="newAttributeInfo">新属性</param> /// <param name="oldAttributeInfo">原属性</param> public void UpdateAttribute(AttributeInfo attributeInfo) { DbParameter[] parms = { GenerateInParam("@name", SqlDbType.NChar, 30, attributeInfo.Name), GenerateInParam("@cateid", SqlDbType.SmallInt,2,attributeInfo.CateId), GenerateInParam("@attrgroupid", SqlDbType.SmallInt,2,attributeInfo.AttrGroupId), GenerateInParam("@showtype", SqlDbType.TinyInt,1,attributeInfo.ShowType), GenerateInParam("@isfilter", SqlDbType.TinyInt,1,attributeInfo.IsFilter), GenerateInParam("@displayorder", SqlDbType.Int,4,attributeInfo.DisplayOrder), GenerateInParam("@attrid", SqlDbType.SmallInt, 2, attributeInfo.AttrId) }; string commandText = string.Format("UPDATE [{0}attributes] SET [name]=@name,[cateid]=@cateid,[attrgroupid]=@attrgroupid,[showtype]=@showtype,[isfilter]=@isfilter,[displayorder]=@displayorder WHERE [attrid]=@attrid", RDBSHelper.RDBSTablePre); int effetRowCount = RDBSHelper.ExecuteNonQuery(CommandType.Text, commandText, parms); if (effetRowCount > 0) { commandText = string.Format("UPDATE [{0}attributevalues] SET [attrname]='{1}',[attrdisplayorder]={2},[attrshowtype]={3} WHERE [attrid]={4}", RDBSHelper.RDBSTablePre, attributeInfo.Name, attributeInfo.DisplayOrder, attributeInfo.ShowType, attributeInfo.AttrId); RDBSHelper.ExecuteNonQuery(CommandType.Text, commandText); } }