/// <summary> /// 新增产品类别 /// </summary> /// <returns></returns> public ActionResult Add() { string CateNum = WebUtil.GetFormValue <string>("CateNum"); string CompanyID = WebUtil.GetFormValue <string>("CompanyID"); string CateName = WebUtil.GetFormValue <string>("CateName"); string Remark = WebUtil.GetFormValue <string>("Remark"); string CreateUser = WebUtil.GetFormValue <string>("CreateUser"); string ParentNum = WebUtil.GetFormValue <string>("ParentNum"); ProductCategoryEntity entity = new ProductCategoryEntity(); entity.CateName = CateName; entity.IsDelete = (int)EIsDelete.NotDelete; entity.CreateTime = DateTime.Now; entity.CreateUser = CreateUser; entity.Remark = Remark; entity.ParentNum = ParentNum; entity.CompanyID = CompanyID; ProductCategoryProvider provider = new ProductCategoryProvider(CompanyID); int line = provider.Add(entity); DataResult result = new DataResult(); if (line > 0) { result.Code = (int)EResponseCode.Success; result.Message = "产品类别新增成功"; } else { result.Code = (int)EResponseCode.Exception; result.Message = "产品类别新增失败"; } return(Content(JsonHelper.SerializeObject(result))); }
public void Test_Add_QueryById_Update_Delete_ProductCategoryProvider() { var category = new Category { Name = "catagory1", Description = "Hello description!", Image = "", PageSize = 10, Published = true, Deleted = false, DisplayOrder = 1, UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var product = new Product { Name = "Product1", UtcCreationDate = DateTime.UtcNow, UtcUpdateDate = DateTime.UtcNow }; var productCategory = new ProductCategory { IsFeaturedProduct = false, DisplayOrder = 2, Product = product, Category = category }; Mock <IEntityFileProvider> entityFileProvider = new Mock <IEntityFileProvider>(); var categoryProvider = new CategoryProvider(new NoDI_NHibernateContextFactory(), entityFileProvider.Object); //Add brand new ProductProvider(new NoDI_NHibernateContextFactory()).Add(product); categoryProvider.Add(category); provider.Add(productCategory); Console.WriteLine("Add OK!"); //QueryBy var productCategoryQueryBy = provider.QueryById(productCategory.Id); Assert.IsNotNull(productCategoryQueryBy); Console.WriteLine("QueryBy OK!"); //update productCategory.DisplayOrder = 5; provider.Update(productCategory); var productCategoryUpdate = provider.QueryById(productCategory.Id); Assert.AreEqual(5, productCategoryUpdate.DisplayOrder); Console.WriteLine("Update OK!"); //Delete provider.Delete(productCategory); var productCategoryDelete = provider.QueryById(productCategory.Id); Assert.IsNull(productCategoryDelete); Console.WriteLine("Delete OK!"); }
public ActionResult Edit() { string cateNum = WebUtil.GetFormValue <string>("num", string.Empty); string cateName = WebUtil.GetFormValue <string>("name", string.Empty); string remark = WebUtil.GetFormValue <string>("remark", string.Empty); if (cateNum.IsEmpty()) { ProductCategoryEntity entity = new ProductCategoryEntity(); entity.CateNum = SequenceProvider.GetSequence(typeof(ProductCategoryEntity)); entity.CateName = cateName; entity.IsDelete = (int)EIsDelete.NotDelete; entity.CreateTime = DateTime.Now; entity.Remark = remark; entity.CreateUser = this.LoginUserCode; ProductCategoryProvider provider = new ProductCategoryProvider(); int line = provider.Add(entity); if (line > 0) { this.ReturnJson.AddProperty("d", "success"); } } else { ProductCategoryEntity entity = new ProductCategoryEntity(); entity.CateNum = cateNum; entity.CateName = cateName; entity.Remark = remark; ProductCategoryProvider provider = new ProductCategoryProvider(); int line = provider.Update(entity); if (line > 0) { this.ReturnJson.AddProperty("d", "success"); } } return(Content(this.ReturnJson.ToString())); }
public static bool NewProductCategory(ProductCategoryEntity category) { return(ProductCategoryProvider.Add(category)); }