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 FindItemCategoryByItemCategoryId()
        {
            //Arrange
            int test = 1;

            //Act
            var result = itemCategoryService.FindItemCategoryByItemCategoryId(test);

            //Assert
            Assert.AreEqual("Clip", result.Name);
        }
        public ItemCategoryViewModel GetItemCategory(string id)
        {
            ItemCategory itemcategory = itemcategoryService.FindItemCategoryByItemCategoryId(int.Parse(id));

            return(new ItemCategoryViewModel()
            {
                ItemCategoryId = itemcategory.ItemCategoryId,
                Name = itemcategory.Name,
                Description = itemcategory.Description,
                Status = itemcategory.Status.StatusId
            });
        }
        public ActionResult Save(EditItemFinalViewModel model)
        {
            Console.WriteLine(model);
            SaveImage(model);
            string    error        = "";
            Item      newItem      = new Item();
            ItemPrice newItemPrice = new ItemPrice();

            if (model.ItemCode != null)
            {
                if (itemService.FindItemByItemCode(model.ItemCode) == null)
                {
                    //for inventory
                    int quantity = 0;
                    //new item
                    newItem.ItemCode        = model.ItemCode;
                    newItem.CreatedDateTime = DateTime.Now;
                    newItem.CreatedBy       = userService.FindUserByEmail(System.Web.HttpContext.Current.User.Identity.GetUserName());
                    newItem.Name            = model.ItemName;
                    newItem.Description     = model.Description;
                    newItem.Uom             = model.Uom;
                    newItem.ItemCategory    = categoryService.FindItemCategoryByItemCategoryId(model.CategoryId);
                    newItem.Bin             = model.Bin;
                    newItem.ReorderLevel    = model.ReorderLevel;
                    newItem.ReorderQuantity = model.ReorderQuantity;
                    newItem.Status          = new StatusService(context).FindStatusByStatusId(1);
                    try
                    {
                        itemService.Save(newItem, quantity);
                        ProcessItemPrice(model);
                    }
                    catch (Exception e)
                    {
                        error = "Error in item save";
                        Console.WriteLine("An error occurred in Item Save: '{0}'", e);
                    }
                }
                else
                {
                    //update exiting item
                    Item             current = itemService.FindItemByItemCode(model.ItemCode);
                    List <ItemPrice> k       = itemPriceService.FindItemPriceByItemCode(current.ItemCode);
                    foreach (ItemPrice i in k)
                    {
                        itemPriceService.DeleteItemPrice(i);
                    }
                    current.Description     = model.Description;
                    current.ReorderLevel    = model.ReorderLevel;
                    current.ReorderQuantity = model.ReorderQuantity;
                    current.Bin             = model.Bin;
                    current.Uom             = model.Uom;
                    current.Status          = new StatusService(context).FindStatusByStatusId(1);
                    current.UpdatedBy       = userService.FindUserByEmail(System.Web.HttpContext.Current.User.Identity.GetUserName());
                    current.UpdatedDateTime = DateTime.Now;
                    int quantity = current.Inventory.Quantity;
                    try
                    {
                        itemService.Save(current, quantity);
                        if (!ProcessItemPrice(model))
                        {
                            //write error case
                        }
                    }
                    catch (Exception e)
                    {
                        error = "Error in item update";
                        Console.WriteLine("An error occurred in Item Update: '{0}'", e);
                    }
                }
            }
            else
            {
                //show erro bcuz no item code
                error = "Item code comes as null";
            }

            return(RedirectToAction("Index", "Inventory"));
            //return new JsonResult { };
        }