public void SetPersistentMenuTest()
        {
            LocalizedMenuItem lmi = new LocalizedMenuItem();

            lmi.Locale = LocalizedMenuItem.DefaultLocale;
            lmi.Items  = new List <IMenuItem>();

            NestedMenuItem nested = new NestedMenuItem()
            {
                Title = "My Account",
                Items = new List <IMenuItem>()
            };

            nested.Items.Add(new PostbackMenuItem()
            {
                Title = "Pay Bill", Payload = "PAYBILL_PAYLOAD"
            });
            nested.Items.Add(new UrlMenuItem()
            {
                Title = "Latest News", Url = "https://www.messenger.com/"
            });

            lmi.Items.Add(nested);

            PersistentMenu menu = new PersistentMenu();

            menu.Items = new List <LocalizedMenuItem>();
            menu.Items.Add(lmi);

            bool result = client.SetPersistentMenu(menu).Result;

            Trace.WriteLine(("Success: {0}".Format(result)));
        }
예제 #2
0
        //MenuItem Object Scope Validation check the entire object for validity...
        private byte MenuItemIsValid(NestedMenuItem item, out string errorMessage)
        {   //validate key
            errorMessage = "";
            if (string.IsNullOrEmpty(item.MenuItemID))
            {
                errorMessage = "ID Is Required.";
                return(1);
            }
            MenuItem     menuItem    = MenuItemList.FirstOrDefault(q => q.AutoID == item.AutoID);
            EntityStates entityState = GetMenuItemState(menuItem);

            if (entityState == EntityStates.Added && MenuItemExists(item.MenuItemID))
            {
                errorMessage = "Item All Ready Exists.";
                return(1);
            }
            //check cached list for duplicates...
            int count = MenuItemList.Count(q => q.MenuItemID == item.MenuItemID);

            if (count > 1)
            {
                errorMessage = "Item All Ready Exists.";
                return(1);
            }
            //validate Description
            if (string.IsNullOrEmpty(item.Name))
            {
                errorMessage = "Name Is Required.";
                return(1);
            }
            //a value of 2 is pending changes...
            //On Commit we will give it a value of 0...
            return(2);
        }
예제 #3
0
        private bool NewMenuItem(string itemID)
        {//need to fix this...
            MenuItem newItem = new MenuItem();

            //all new records will be give a negative int autoid...
            //when they are updated then sql will generate one for them overiding this set value...
            //it will allow us to give uniqueness to the tempory new records...
            //Before they are updated to the entity and given an autoid...
            //we use a negative number and keep subtracting by 1 for each new item added...
            //This will allow it to alwasy be unique and never interfere with SQL's positive autoid...
            _newMenuItemAutoId = _newMenuItemAutoId - 1;
            newItem.AutoID     = _newMenuItemAutoId;
            newItem.MenuItemID = itemID;
            newItem.CompanyID  = ClientSessionSingleton.Instance.CompanyID;
            //new items will be added to selected item
            newItem.ParentMenuID = SelectedMenuItem.MenuItemID;
            //add it to the repository list
            MenuItemList.Add(newItem);
            _serviceAgent.AddToMenuItemRepository(newItem);

            //add it to the treeviewList
            NestedMenuItem newNestedItem = new NestedMenuItem(newItem);

            newNestedItem.IsValid         = 1;
            newNestedItem.NotValidMessage = "New Record Key Field/s Are Required.";
            SelectedMenuItem.Children.Add(newNestedItem);

            AllowEdit = true;
            Dirty     = false;
            return(true);
        }
예제 #4
0
        public static void SetPropertyValue(this NestedMenuItem myObj, object propertyName, object propertyValue)
        {
            var propInfo = typeof(NestedMenuItem).GetProperty((string)propertyName);

            if (propInfo != null)
            {
                propInfo.SetValue(myObj, propertyValue, null);
            }
        }
예제 #5
0
        private bool Delete(NestedMenuItem item)
        {//deletes are done indenpendently of the repository as a delete will not commit
            //dirty records it will simply just delete the record...
            MenuItem menuItem = MenuItemList.FirstOrDefault(q => q.AutoID == item.AutoID);

            _serviceAgent.DeleteFromMenuItemRepository(menuItem);
            //remove it from the cache repository list
            MenuItemList.Remove(menuItem);
            return(true);
        }
예제 #6
0
 private void getNestedChidlren(NestedMenuItem pnmi)
 {
     foreach (NestedMenuItem cnmi in _flatNestedMenuItemList
              .Where(nmi => nmi.ParentMenuID == pnmi.MenuItemID)
              .OrderBy(a => a.DisplayOrder)
              .ToList())
     {
         pnmi.Children.Add(cnmi);
         getNestedChidlren(cnmi);
     }
 }
예제 #7
0
        //commits repository to the db...
        private bool Commit()
        {   //reset UI state manage fields...
            NestedMenuItem root = TreeNestedMenuItemList.FirstOrDefault(q => (q.ParentMenuID == null || q.ParentMenuID.Equals(string.Empty)) &&
                                                                        q.CompanyID == ClientSessionSingleton.Instance.CompanyID);

            _serviceAgent.CommitMenuItemRepository();
            //recurse tree clear and set seed autoids
            ResetTreeTempFields(root);
            Dirty       = false;
            AllowCommit = false;
            return(true);
        }
예제 #8
0
 public void RemoveNestedItem(NestedMenuItem parent, long autoID)
 {
     foreach (NestedMenuItem child in parent.Children)
     {
         if (child.AutoID == autoID)
         {
             parent.Children.Remove(child);
             return;
         }
         RemoveNestedItem(child, autoID);
     }
 }
예제 #9
0
        public static string GetPropertyType(this NestedMenuItem myObj, string propertyName)
        {
            var propInfo = typeof(NestedMenuItem).GetProperty(propertyName);

            if (propInfo != null)
            {
                return(propInfo.PropertyType.Name.ToString());
            }
            else
            {
                return(null);
            }
        }
예제 #10
0
        public static object GetPropertyValue(this NestedMenuItem myObj, string propertyName)
        {
            var propInfo = typeof(NestedMenuItem).GetProperty(propertyName);

            if (propInfo != null)
            {
                return(propInfo.GetValue(myObj, null));
            }
            else
            {
                return(string.Empty);
            }
        }
예제 #11
0
 private void CheckForInvalidRows(NestedMenuItem parent)
 {
     if (_rowsValid)
     {
         foreach (NestedMenuItem child in parent.Children)
         {
             if (child.IsValid == 1)
             {
                 _rowsValid = false;
                 return;
             }
             if (_rowsValid)
             {
                 CheckForInvalidRows(child);
             }
         }
     }
 }
예제 #12
0
        public void DeleteMenuItemCommand()
        {     //ToDo fix delete logic
            try
            { //delete in repository
                Delete(SelectedMenuItem);

                //remove it from the tree nested list
                NestedMenuItem root = TreeNestedMenuItemList.FirstOrDefault(q => (q.ParentMenuID == null || q.ParentMenuID.Equals(string.Empty)) &&
                                                                            q.CompanyID == ClientSessionSingleton.Instance.CompanyID);
                //need to itterate tree and find the item and remove it from the tree list...
                RemoveNestedItem(root, SelectedMenuItem.AutoID);
            }//we try catch company delete as it may be used in another table as a key...
            ////As well we will force a refresh to sqare up the UI after the botched delete...
            catch
            {
                NotifyMessage("MenuItem/s Can Not Be Deleted.  Contact XERP Admin For More Details.");
                //    Refresh();
            }
        }
예제 #13
0
        //udpate merely updates the repository a commit is required
        //to commit it to the db...
        private bool Update(NestedMenuItem item, string propertyName, object propertyValue)
        {//get the menuItem from the Repository List...
            MenuItem menuItem = MenuItemList.FirstOrDefault(q => q.AutoID == item.AutoID);

            //Set the edited field when present...
            if (!string.IsNullOrEmpty(propertyName))
            {
                menuItem.SetPropertyValue(propertyName, propertyValue);
            }
            //update the repository with the field change...
            _serviceAgent.UpdateMenuItemRepository(menuItem);
            Dirty = true;
            if (CommitIsAllowed())
            {
                AllowCommit = true;
            }
            else
            {
                AllowCommit = false;
            }
            return(AllowCommit);
        }
예제 #14
0
        //Object.Property Scope Validation...
        private bool MenuItemIsValid(NestedMenuItem item, _menuItemValidationProperties validationProperties, out string errorMessage)
        {
            errorMessage = "";
            switch (validationProperties)
            {
            case _menuItemValidationProperties.MenuItemID:
                //validate key
                if (string.IsNullOrEmpty(item.MenuItemID))
                {
                    errorMessage = "ID Is Required.";
                    return(false);
                }
                MenuItem     menuItem    = MenuItemList.FirstOrDefault(q => q.AutoID == item.AutoID);
                EntityStates entityState = GetMenuItemState(menuItem);
                if (entityState == EntityStates.Added && MenuItemExists(item.MenuItemID))
                {
                    errorMessage = "Item All Ready Exists...";
                    return(false);
                }
                //check cached list for duplicates...
                int count = MenuItemList.Count(q => q.MenuItemID == item.MenuItemID);
                if (count > 1)
                {
                    errorMessage = "Item All Ready Exists...";
                    return(false);
                }
                break;

            case _menuItemValidationProperties.Name:
                //validate Description
                if (string.IsNullOrEmpty(item.Name))
                {
                    errorMessage = "Description Is Required.";
                    return(false);
                }
                break;
            }
            return(true);
        }
예제 #15
0
 private void ResetTreeTempFields(NestedMenuItem parent)
 {
     foreach (NestedMenuItem child in parent.Children)
     {
         child.IsValid         = 0;
         child.NotValidMessage = "";
         //autoID is set a negative value until it is seeded from the db...
         if (child.AutoID < 0)
         {
             //locate the record to fetch the seeded autoid value...
             MenuItem menuItem = MenuItemList.FirstOrDefault(q => q.MenuItemID == child.MenuItemID &&
                                                             q.CompanyID == ClientSessionSingleton.Instance.CompanyID);
             child.AutoID = menuItem.AutoID;
         }
         //if it is selected we need to modify SelectedMenuItem as well...
         if (child.IsSelected == true)
         {
             SelectedMenuItem.IsValid         = 0;
             SelectedMenuItem.NotValidMessage = "";
         }
         ResetTreeTempFields(child);
     }
 }