public ValueListEditAdminViewModel(StoreFront storeFront, UserProfile userProfile, ValueList valueList, string activeTab, bool isStoreAdminEdit = false, bool isReadOnly = false, bool isDeletePage = false, bool isCreatePage = false, string sortBy = "", bool? sortAscending = true)
 {
     if (storeFront == null)
     {
         throw new ArgumentNullException("storeFront");
     }
     if (userProfile == null)
     {
         throw new ArgumentNullException("userProfile");
     }
     if (valueList == null)
     {
         throw new ArgumentNullException("valueList", "valueList cannot be null");
     }
     this.IsStoreAdminEdit = isStoreAdminEdit;
     this.IsActiveDirect = valueList.IsActiveDirect();
     this.IsActiveBubble = valueList.IsActiveBubble();
     this.IsReadOnly = isReadOnly;
     this.IsDeletePage = isDeletePage;
     this.IsCreatePage = isCreatePage;
     this.ActiveTab = activeTab;
     this.SortBy = sortBy;
     this.SortAscending = sortAscending;
     LoadValues(storeFront, userProfile, valueList);
 }
        public ActionResult Create(ValueList valueList)
        {
            if (ModelState.IsValid)
            {
                valueList = GStoreDb.ValueLists.Create(valueList);
                valueList.UpdateAuditFields(CurrentUserProfileOrThrow);
                valueList = GStoreDb.ValueLists.Add(valueList);
                GStoreDb.SaveChanges();
                AddUserMessage("Value List Created", "Value List '" + valueList.Name.ToHtml() + "' [" + valueList.ValueListId + "] Created Successfully", UserMessageType.Success);
                return RedirectToAction("Index");
            }
            int? clientId = null;
            if (valueList.ClientId != default(int))
            {
                clientId = valueList.ClientId;
            }

            this.BreadCrumbsFunc = htmlHelper => this.ValueListBreadcrumb(htmlHelper, valueList.ClientId, valueList);
            return View(valueList);
        }
        protected void LoadValues(StoreFront storeFront, UserProfile userProfile, ValueList valueList)
        {
            if (valueList == null)
            {
                return;
            }

            this.ValueList = valueList;
            this.Client = valueList.Client;
            this.ClientId = (valueList.Client == null ? 0 : valueList.ClientId);
            this.CreateDateTimeUtc = valueList.CreateDateTimeUtc;
            this.CreatedBy = valueList.CreatedBy;
            this.CreatedBy_UserProfileId = valueList.CreatedBy_UserProfileId;
            this.Description = valueList.Description;
            this.EndDateTimeUtc = valueList.EndDateTimeUtc;
            this.IsPending = valueList.IsPending;
            this.Name = valueList.Name;
            this.Order = valueList.Order;
            this.StartDateTimeUtc = valueList.StartDateTimeUtc;
            this.UpdateDateTimeUtc = valueList.UpdateDateTimeUtc;
            this.UpdatedBy = valueList.UpdatedBy;
            this.UpdatedBy_UserProfileId = valueList.UpdatedBy_UserProfileId;
            this.ValueListItems = valueList.ValueListItems;
            this.ValueListId = valueList.ValueListId;
            this._valueListItemEditAdminViewModels = null;
        }
예제 #4
0
        public static void SetDefaultsForNew(this ValueListItem valueListItem, ValueList valueList)
        {
            valueListItem.Name = "New Value";
            valueListItem.Order = 100;
            if (valueList != null)
            {
                valueListItem.ValueList = valueList;
                valueListItem.ValueListId = valueList.ValueListId;
                valueListItem.ClientId = valueList.ClientId;
                valueListItem.Client = valueList.Client;
                valueListItem.Order = (valueList.ValueListItems.Count == 0) ? 100 : valueList.ValueListItems.Max(vl => vl.Order) + 10;
                if (valueList.ValueListItems.Any(vl => vl.Name.ToLower() == valueListItem.Name.ToLower()))
                {
                    int index = 1;
                    do
                    {
                        index++;
                        valueListItem.Name = "New Value " + index;

                    } while (valueList.ValueListItems.Any(vl => vl.Name.ToLower() == valueListItem.Name.ToLower()));
                }
            }

            valueListItem.Description = valueListItem.Name;
            valueListItem.IsPending = false;
            valueListItem.EndDateTimeUtc = DateTime.UtcNow.AddYears(100);
            valueListItem.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
        }
        public ActionResult Edit(ValueList valueList)
        {
            if (ModelState.IsValid)
            {
                valueList.UpdateAuditFields(CurrentUserProfileOrThrow);
                valueList = GStoreDb.ValueLists.Update(valueList);
                GStoreDb.SaveChanges();
                AddUserMessage("Value List Updated", "Changes saved successfully to Value List '" + valueList.Name.ToHtml() + "' [" + valueList.ValueListId + "]", UserMessageType.Success);
                return RedirectToAction("Index");
            }

            this.BreadCrumbsFunc = htmlHelper => this.ValueListBreadcrumb(htmlHelper, valueList.ClientId, valueList);
            return View(valueList);
        }
예제 #6
0
 protected MvcHtmlString ValueListItemsBreadcrumb(HtmlHelper htmlHelper, ValueList valueList, bool ShowAsLink = false)
 {
     return new MvcHtmlString(
         ValueListBreadcrumb(htmlHelper, valueList.ClientId, valueList, true).ToHtmlString()
         + " -> "
         + (ShowAsLink ? htmlHelper.ActionLink("List Items", "ListItemIndex", "ValueListSysAdmin", new { id = valueList.ValueListId }, null).ToHtmlString() : "List Items")
         );
 }
예제 #7
0
 protected MvcHtmlString ValueListBreadcrumb(HtmlHelper htmlHelper, int? clientId, ValueList valueList, bool ShowAsLink = false)
 {
     RouteValueDictionary routeData = null;
     string name = "(unknown)";
     bool showLink = false;
     if (valueList != null)
     {
         if (valueList.ValueListId == 0)
         {
             name = "New";
         }
         else
         {
             showLink = ShowAsLink;
             routeData = new RouteValueDictionary(new { id = valueList.ValueListId });
             name = "'" + valueList.Name + "' [" + valueList.ValueListId + "]";
         }
     }
     return new MvcHtmlString(
         ValueListsBreadcrumb(htmlHelper, clientId, true).ToHtmlString()
         + " -> "
         + (showLink ? htmlHelper.ActionLink(name, "Details", "ValueListSysAdmin", routeData, null).ToHtmlString() : name)
         );
 }
예제 #8
0
        public static bool ValidateValueListFastAddItemName(this IGstoreDb db, GStoreData.ControllerBase.BaseController controller, string name, ValueList valueList, int? currentValueListItemId)
        {
            string nameField = "fastAddValueListItem";

            if (string.IsNullOrWhiteSpace(name))
            {
                string errorMessage = "Name is required \n Please enter a unique name for this Value List Item";
                controller.ModelState.AddModelError(nameField, errorMessage);
                return false;
            }

            ValueListItem conflict = valueList.ValueListItems.Where(p => p.Name.ToLower() == name.ToLower() && (p.ValueListId != currentValueListItemId)).FirstOrDefault();

            if (conflict == null)
            {
                return true;
            }

            string errorConflictMessage = "Name '" + name + "' is already in use for Value List Item '" + conflict.Name + "' [" + conflict.ValueListItemId + "] in Client '" + conflict.Client.Name.ToHtml() + "' [" + conflict.ClientId + "]. \n You must enter a unique Name or change the conflicting Value List Item Name.";

            controller.ModelState.AddModelError(nameField, errorConflictMessage);
            return false;
        }