public JsonResult CreateItem(ItemModel model)
        {
            if (!ModelState.IsValid)
            {
                return Json(new
                {
                    Result = "ERROR",
                    Message = "Form is not valid! " +
                    "Please correct it and try again."
                });
            }

            if (!User.Identity.IsAuthenticated)
            {
                return Json(new
                {
                    Result = "ERROR",
                    Message = "You need to log in to add an item."
                });
            }

            if (!User.IsInRole("Officer"))
            {
                return Json(new
                {
                    Result = "ERROR",
                    Message = "You do not have the authority to create a new inventory item."
                });
            }
            try
            {
                JourListDMContainer dm = new JourListDMContainer();

                StandardItem item = new StandardItem();

                item.Description = model.Description;
                //if (model.Hyperlink != null) item.Hyperlink = model.Hyperlink;
                //if (model.Barcode != null) item.Barcode = model.Barcode;
                item.ItemCategory = dm.ItemCategories.Single(z => z.Id == model.CategoryId);
                item.UnitType = dm.UnitTypes.Single(z => z.Id == model.UnitTypeId);

                dm.AddToItems(item);
                dm.SaveChanges();

                model.Id = item.Id;

                return Json(new { Result = "OK", Record = model });
            }
            catch (Exception e)
            {
                return Json(new { Result = "ERROR", Message = e.Message });
            }
        }
        public JsonResult CreateItem(ItemModel model)
        {
            if (!ModelState.IsValid)
                return Json(new
                {
                    Result = "ERROR",
                    Message = "Form is not valid! " +
                    "Please correct it and try again."
                });

            if (!User.Identity.IsAuthenticated)
                return Json(new
                {
                    Result = "ERROR",
                    Message = "You need to log in to add personal items."
                });

            try
            {
                JourListDMContainer dm = new JourListDMContainer();
                var member = dm.Members.SingleOrDefault(z => z.Name == User.Identity.Name);

                // If the item exists but is inactive, just reactivate it.
                PersonalItem item;
                if ( (item = member.PersonalItems.SingleOrDefault(z => z.Description == model.Description)) != null)
                {
                    if (item.Active == false)
                        item.Active = true;
                    else
                        return Json(new
                        {
                            Result = "ERROR",
                            Message = "An active item by this description already exists"
                        });
                }
                // Otherwie create a new personal item
                else
                {
                    item = new PersonalItem();
                    item.Description = model.Description;
                    //if (model.Hyperlink != null) item.Hyperlink = model.Hyperlink;
                    //if (model.Barcode != null) item.Barcode = model.Barcode;
                    item.ItemCategory = dm.ItemCategories.Single(z => z.Id == model.CategoryId);
                    item.UnitType = dm.UnitTypes.Single(z => z.Id == model.UnitTypeId);
                    item.Member = member;
                    dm.AddToItems(item);
                    dm.SaveChanges();
                    // Hookup our model with the new jourId number
                    model.Id = item.Id;
                }

                Inventory inv;
                if ((inv = this.AddToInventory(model)) == null)
                    return Json(new
                    {
                        Result = "ERROR",
                        Message = "An active inventory for this item already exists"
                    });

                // Relevant inventory for jTable's purposes
            //                model.Id = item.Id;
                model.IsPersonal = item is PersonalItem;

                return Json(new { Result = "OK", Record = model });
            }
            catch (Exception e)
            {
                return Json(new { Result = "ERROR", Message = e.Message });
            }
        }