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)); }
/// <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)); }