public void EditItemCategoryTest() { //Arrange string expected = "Testing EditSupplier"; //Instantiate controller ItemCategoryController controller = new ItemCategoryController() { CurrentUserName = "******", context = this.context }; controller.ModelState.Clear(); //Assemble a ItemCategory ViewModel from existing test object ItemCategory ic = context.ItemCategory.Where(x => x.Name == "TEST").First(); ItemCategoryViewModel VM = new ItemCategoryViewModel() { ItemCategoryId = ic.ItemCategoryId, Name = ic.Name, Description = expected }; //Act //pass ViewModel to controller controller.Save(VM); var result = itemcategoryRepository.FindById(VM.ItemCategoryId); //Assert //check that entry has been updated in db Assert.AreEqual(expected, result.Description); }
public void AddNewItemCategoryTest() { //Arrange //Instantiate controller ItemCategoryController controller = new ItemCategoryController() { CurrentUserName = "******", context = this.context }; controller.ModelState.Clear(); //create new ViewModel to Save via controller ItemCategoryViewModel newItemCategory = new ItemCategoryViewModel() { ItemCategoryId = IdService.GetNewItemCategoryId(context), Name = "TEST" }; //Act ActionResult result = controller.Save(newItemCategory); //Assert Assert.IsNotNull(result); }
public ActionResult ItemCategoryView() { ItemCategoryViewModel model = new ItemCategoryViewModel(); model.CategoryList = db.category; model.ItemCategoryList = db.itemCategory; ViewBag.CategoryId = new SelectList(db.category, "Id", "CategoryName", model.CategoryId); return(View(model)); }
public ActionResult ItemCategoryView(ItemCategoryViewModel model) { model.CategoryList = db.category; model.ItemCategoryList = db.itemCategory; var newItemCategory = new ItemCategory { CategoryId = model.CategoryId, ItemName = model.ItemName }; db.itemCategory.Add(newItemCategory); db.SaveChanges(); ViewBag.CategoryId = new SelectList(db.category, "Id", "CategoryName", model.CategoryId); return(View(model)); }
public ActionResult Save(ItemCategoryViewModel model) { bool status = false; statusService = new StatusService(context); itemcategoryService = new ItemCategoryService(context); userService = new UserService(context); ItemCategory s = new ItemCategory(); if (itemcategoryService.FindItemCategoryByItemCategoryId(model.ItemCategoryId) == null) { //new item category s.ItemCategoryId = IdService.GetNewItemCategoryId(context); //assign user info s.CreatedDateTime = DateTime.Now; s.CreatedBy = userService.FindUserByEmail(CurrentUserName); } else { //existing ItemCategory s = itemcategoryService.FindItemCategoryByItemCategoryId(model.ItemCategoryId); //assign user info into update fields s.UpdatedDateTime = DateTime.Now; s.UpdatedBy = userService.FindUserByEmail(CurrentUserName); } //assign item category info s.Name = model.Name; s.Description = model.Description; s.Status = statusService.FindStatusByStatusId(model.Status); //save info to database if (itemcategoryService.Save(s) != null) { status = true; } //return RedirectToAction("Index", "ItemCategory"); return(new JsonResult { Data = new { status = status } }); }
public void GetItemCategory_ContainResult() { //Arrange //Instantiate controller var controller = new ItemCategoryAPIController { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration(), }; ItemCategory ic = context.ItemCategory.First(); //Act ItemCategoryViewModel result = controller.GetItemCategory(ic.ItemCategoryId.ToString()); //Assert Assert.AreEqual(ic.Name, result.Name); }
// GET: Items public async Task <IActionResult> Index(string itemCategory, string searchString) { // Use LINQ to get list of categories in the Item. IQueryable <string> categoryQuery = from m in _context.Item orderby m.Category select m.Category; var items = from m in _context.Item select m; //first select the items title matched with the passed search string value if (!string.IsNullOrEmpty(searchString)) { items = items.Where(s => s.Title.Contains(searchString)); } //then from the above filtered list filter out the items matching to the given category if (!string.IsNullOrEmpty(itemCategory)) { items = items.Where(x => x.Category == itemCategory); } var itemCategoryVM = new ItemCategoryViewModel { Category = new SelectList(await categoryQuery.Distinct().ToListAsync()), Items = await items.ToListAsync() }; ViewBag.category = new List <String>(await categoryQuery.Distinct().ToListAsync()); //check whether the logged user's role is admin if (_SignInManager.IsSignedIn(User)) { if (User.IsInRole("Admin")) { return(View("AdminProductList", itemCategoryVM)); } return(View(itemCategoryVM)); } return(View(itemCategoryVM)); }
public MainViewModel(TypeViewmodel povm, ItemCategoryViewModel tcvm) { this.TypeViewmodel = povm; this.ItemCategoryViewmodel = tcvm; }
public void SaveItem(ItemCategoryViewModel itemView) { }
public void DeleteItem(ItemCategoryViewModel itemView) { ItemCategoryCollection.Remove(itemView); }