public JsonResult CategoryProducts(int?CategoryID) { Category oCategory = oCategoryService.Find(CategoryID);// .Queryable().ToList(); Models.mCategory omCatg = new Models.mCategory { CategoryID = oCategory.CategoryID, CategoryName = oCategory.CategoryName, Description = oCategory.Description }; omCatg.Products = new List <Product>(); omCatg.Products.Add(new Product { ProductID = 1000 + omCatg.CategoryID, ProductName = omCatg.CategoryName + " - Prod 1", UnitPrice = 100 + omCatg.CategoryID }); omCatg.Products.Add(new Product { ProductID = 2000 + omCatg.CategoryID, ProductName = omCatg.CategoryName + " - Prod 2", UnitPrice = 200 + omCatg.CategoryID }); omCatg.Products.Add(new Product { ProductID = 3000 + omCatg.CategoryID, ProductName = omCatg.CategoryName + " - Prod 3", UnitPrice = 300 + omCatg.CategoryID }); omCatg.Products.Add(new Product { ProductID = 4000 + omCatg.CategoryID, ProductName = omCatg.CategoryName + " - Prod 4", UnitPrice = 400 + omCatg.CategoryID }); omCatg.Products.Add(new Product { ProductID = 5000 + omCatg.CategoryID, ProductName = omCatg.CategoryName + " - Prod 5", UnitPrice = 500 + omCatg.CategoryID }); return(Json(new { data = omCatg.Products }, JsonRequestBehavior.AllowGet)); }
public ActionResult EditCategory(int id) { var Categ = oCategoryService.Find(id); Models.mCategory oCatg = new Models.mCategory { CategoryID = Categ.CategoryID, CategoryName = Categ.CategoryName, Description = Categ.Description, RowVersion = Categ.RowVersion }; return(View("AddCategory", oCatg)); }
public void CategoryTitleMethod_Test() { // Arrange Models.mCategory Catg = new Models.mCategory { CategoryID = 1, CategoryName = "TestName", Description = "Test Description" }; // Act // Assert Assert.AreEqual(Catg.CategoryTitle, Catg.Title()); }
public void CategoryTitle_Test(string sName, string sDesc, string sResult) { // Arrange Models.mCategory Catg = new Models.mCategory { CategoryID = 1, CategoryName = sName, Description = sDesc }; // Act // Assert Assert.AreEqual(sResult, Catg.CategoryTitle); }
public JsonResult GetCategories() { List <Category> Categories = oCategoryService.Queryable().ToList(); List <Models.mCategory> mCatg = new List <Models.mCategory>(); foreach (var o in Categories) { Models.mCategory omCatg = new Models.mCategory { CategoryID = o.CategoryID, CategoryName = o.CategoryName, Description = o.Description }; mCatg.Add(omCatg); } return(Json(new { data = mCatg }, JsonRequestBehavior.AllowGet)); }
public ActionResult AddCategory(Models.mCategory oCategory) { //Mapper.Initialize(cfg => cfg.CreateMap<Models.mCategory , Category>()); var config = new MapperConfiguration(cfg => cfg.CreateMap <Models.mCategory, Category>()); var mapper = config.CreateMapper(); // Mapper(config); Category oCatg = mapper.Map <Category>(oCategory); //Category oCatg = Mapper.Map<Category>(oCategory); if (ModelState.IsValid) { try { if (oCatg.CategoryID == 0) { oCategoryService.Insert(oCatg); } else { oCategoryService.Update(oCatg); } oUnitofWork.SaveChanges(); } catch (Exception ex) { ModelState.AddModelError("SOME ERROR", ex.Message); return(Json(new { success = false, message = "Error while saving data. Data not saved." }, JsonRequestBehavior.AllowGet)); throw ex; } return(Json(new { success = true, message = "Saved Successfully." }, JsonRequestBehavior.AllowGet)); } else { return(View(oCategory)); } }