public ValueListItemEditAdminViewModel(ValueListEditAdminViewModel valueListViewModel, ValueListItem valueListItem, int index)
        {
            if (valueListViewModel == null)
            {
                throw new ArgumentNullException("valueListViewModel");
            }

            if (valueListViewModel.ValueList == null)
            {
                throw new ArgumentNullException("valueListViewModel.ValueList", "valueListViewModel.ValueList cannot be null. make sure edit page sets this after post");
            }

            this.Index = index;

            this.ValueListEditAdminViewModel = valueListViewModel;
            this.ValueList = valueListViewModel.ValueList;
            this.ValueListId = valueListViewModel.ValueList.ValueListId;

            this.IsStoreAdminEdit = valueListViewModel.IsStoreAdminEdit;
            this.IsReadOnly = valueListViewModel.IsReadOnly;
            this.IsDeletePage = valueListViewModel.IsDeletePage;
            this.IsCreatePage = valueListViewModel.IsCreatePage;
            this.ActiveTab = valueListViewModel.ActiveTab;

            FillListsIfEmpty(valueListItem.Client);

            if (valueListItem == null)
            {
                SetDefaults(valueListViewModel);
            }
            else
            if (valueListItem != null)
            {
                this.Name = valueListItem.Name;
                this.Order = valueListItem.Order;
                this.Description = valueListItem.Description;
                this.IsInteger = valueListItem.IsInteger;
                this.IntegerValue = valueListItem.IntegerValue;
                this.IsString = valueListItem.IsString;
                this.StringValue = valueListItem.StringValue;
                this.ValueListItemId = valueListItem.ValueListItemId;

                this.IsPending = valueListItem.IsPending;
                this.StartDateTimeUtc = valueListItem.StartDateTimeUtc;
                this.EndDateTimeUtc = valueListItem.EndDateTimeUtc;
                this.IsActiveDirect = valueListItem.IsActiveDirect();
                this.IsActiveBubble = valueListItem.IsActiveBubble();
            }
        }
        public ActionResult ListItemEdit(ValueListItem valueListItem)
        {
            ValueList valueList = GStoreDb.ValueLists.FindById(valueListItem.ValueListId);
            if (valueListItem == null)
            {
                return HttpNotFound("Value List not found. Value List id: " + valueListItem.ValueListId);
            }

            if (ModelState.IsValid)
            {
                valueListItem.UpdateAuditFields(CurrentUserProfileOrThrow);
                valueListItem = GStoreDb.ValueListItems.Update(valueListItem);
                GStoreDb.SaveChanges();
                AddUserMessage("Value List Item Updated", "Changes saved successfully to Value List Item '" + valueListItem.Name.ToHtml() + "' [" + valueListItem.ValueListItemId + "]", UserMessageType.Success);
                return RedirectToAction("ListItemIndex", new { id = valueListItem.ValueListId });
            }

            valueListItem.ValueList = valueList;
            this.BreadCrumbsFunc = htmlHelper => this.ValueListItemBreadcrumb(htmlHelper, valueListItem, false);
            return View(valueListItem);
        }
        public ActionResult ListItemCreate(ValueListItem valueListItem)
        {
            if (valueListItem.ValueListId == default(int))
            {
                return HttpBadRequest("Value List id is 0");
            }

            IGstoreDb db = GStoreDb;
            ValueList valueList = db.ValueLists.FindById(valueListItem.ValueListId);
            if (valueList == null)
            {
                return HttpNotFound("Value List not found. Value List id: " + valueListItem.ValueListId);
            }

            if (valueList.ValueListItems.Any(vl => vl.Name.ToLower() == valueListItem.Name.ToLower()))
            {
                ModelState.AddModelError("Name", "An item with name '" + valueListItem.Name + "' already exists. Choose a new name or edit the original value.");
            }

            if (ModelState.IsValid)
            {
                valueListItem.ClientId = valueList.ClientId;
                valueListItem.ValueListId = valueList.ValueListId;
                valueListItem = GStoreDb.ValueListItems.Add(valueListItem);
                GStoreDb.SaveChanges();
                AddUserMessage("Value List Item Created", "Value List Item '" + valueListItem.Name.ToHtml() + "' [" + valueListItem.ValueListItemId + "] created successfully", UserMessageType.Success);
                return RedirectToAction("ListItemIndex", new { id = valueListItem.ValueListId });
            }

            valueListItem.ValueList = valueList;
            this.BreadCrumbsFunc = htmlHelper => this.ValueListItemBreadcrumb(htmlHelper, valueListItem, false);
            return View(valueListItem);
        }
 protected MvcHtmlString ValueListItemBreadcrumb(HtmlHelper htmlHelper, ValueListItem valueListItem, bool ShowAsLink = false)
 {
     RouteValueDictionary routeData = null;
     string name = "(unknown)";
     bool showLink = false;
     if (valueListItem != null)
     {
         if (valueListItem.ValueListItemId == 0)
         {
             name = "New";
         }
         else
         {
             showLink = ShowAsLink;
             routeData = new RouteValueDictionary(new { id = valueListItem.ValueListItemId });
             name = "'" + valueListItem.Name + "' [" + valueListItem.ValueListItemId + "]";
         }
     }
     return new MvcHtmlString(
         ValueListItemsBreadcrumb(htmlHelper, valueListItem.ValueList, true).ToHtmlString()
         + " -> "
         + (showLink ? htmlHelper.ActionLink(name, "ListItemDetails", "ValueListSysAdmin", routeData, null).ToHtmlString() : name)
         );
 }