Exemplo n.º 1
0
        public async Task <IActionResult> OnPostCustomLinkAsync([FromBody] AddNavIM im)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid form values submitted."));
            }

            var nav = new Nav
            {
                Id   = 0,
                Text = im.Text.Trim(),
                Type = ENavType.CustomLink,
                Url  = im.Url?.Trim(),
            };

            await navigationService.AddNavToMenuAsync(im.MenuId, im.Index, nav);

            var navVM = new NavVM(nav)
            {
                SettingsUrl = string.Format(NAV_SETTINGS_URL, im.MenuId, im.Index),
                Type        = ENavType.CustomLink,
            };

            return(new JsonResult(navVM));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a nav to menu.
        /// </summary>
        /// <param name="im">Input model of the nav being added.</param>
        /// <returns>
        /// A <see cref="NavVM"/> with SettingsUrl.
        /// </returns>
        public async Task <IActionResult> OnPostAddAsync([FromBody] AddNavIM im)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid form values submitted."));
            }

            // from a menu since menu id is an int
            if (int.TryParse(im.FromId, out int fromId))
            {
                // remove the item from the old menu
                await navigationService.RemoveNavFromMenuAsync((EMenu)fromId, im.OldIndex);
            }

            var nav = new Nav
            {
                Id   = im.Id,
                Text = im.Text.Trim(),
                Type = im.Type,
            };
            await navigationService.AddNavToMenuAsync(im.MenuId, im.Index, nav);

            var navVM = new NavVM(nav)
            {
                SettingsUrl = string.Format(NAV_SETTINGS_URL, im.MenuId, im.Index)
            };

            return(new JsonResult(navVM));
        }
Exemplo n.º 3
0
        public MenuVM(MenuInfo info, IList <Nav> navList, IList <Blog.Models.Page> pages, IList <Category> cats)
        {
            Id          = info.Id;
            Name        = info.Name;
            Description = info.Description;
            Navs        = new List <NavVM>();

            for (int i = 0; i < navList.Count; i++)
            {
                var navVM = new NavVM(navList[i])
                {
                    OrigNavName = NavigationModel.GetOriginalNavTitle(navList[i], pages, cats),
                    SettingsUrl = string.Format(NavigationModel.NAV_SETTINGS_URL, Id, i),
                };
                Navs.Add(navVM);
            }
        }