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 void GetNewItemCategoryIdTest()
        {
            // Arrange
            int expected = context.ItemCategory.OrderByDescending(x => x.ItemCategoryId)
                           .FirstOrDefault().ItemCategoryId + 1;

            // Act
            var result = IdService.GetNewItemCategoryId(context);

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void TestInitialize()
        {
            context                = new ApplicationDbContext();
            itemRepository         = new ItemRepository(context);
            itemcategoryService    = new ItemCategoryService(context);
            itemcategoryRepository = new ItemCategoryRepository(context);

            //create new ItemCategory object and save into DB
            ItemCategory ic = itemcategoryRepository.Save(new ItemCategory()
            {
                ItemCategoryId  = IdService.GetNewItemCategoryId(context),
                Name            = "TEST",
                CreatedDateTime = DateTime.Now
            });
        }
        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 }
            });
        }