/// <summary>
 /// Create a new PersonalItem object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 public static PersonalItem CreatePersonalItem(global::System.Int64 id, global::System.String description)
 {
     PersonalItem personalItem = new PersonalItem();
     personalItem.Id = id;
     personalItem.Description = description;
     return personalItem;
 }
        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 });
            }
        }