You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.3 KiB
61 lines
2.3 KiB
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Security.Claims;
|
|
using Microsoft.AspNetCore.Http;
|
|
using BWPMModels;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using App.Models;
|
|
|
|
namespace APP.ViewComponents
|
|
{
|
|
public class MenuItemsViewComponent : ViewComponent
|
|
{
|
|
List<Object> menuItems = new List<Object>();
|
|
//List<AppMenuItem> menuItems = new List<AppMenuItem>();
|
|
private readonly UserManager<AppUser> _userManager;
|
|
private readonly SignInManager<AppUser> _signInManager;
|
|
|
|
public MenuItemsViewComponent(UserManager<AppUser> userManager, SignInManager<AppUser> signInManager)
|
|
{
|
|
this._userManager = userManager;
|
|
this._signInManager = signInManager;
|
|
|
|
//HttpContext.Session.SetString("usertype","1");
|
|
//string usertype = HttpContext.Session.GetString("usertype");
|
|
menuItems = AppMenuItem.MenuItems("1");
|
|
//if (_signInManager.IsSignedIn(HttpContext.User))
|
|
//{
|
|
// menuItems.Add(new AppMenuItem { id = "999", text = "Login", parentId = "", url = "/Account/Logout" });
|
|
//}
|
|
//else
|
|
//{
|
|
// menuItems.Add(new AppMenuItem { id = "999", text = "Login", parentId = "", url = "/Account/Login" });
|
|
//}
|
|
//// if (state == "" || state == "False")
|
|
////{ menuItems.Add(new AppMenuItem { id = "999", text = "Login", parentId = "", url = "/Account/Login" }); }
|
|
////;
|
|
//ViewBag.menuitems = menuItems;
|
|
//var model = menuItems;
|
|
}
|
|
|
|
public async Task<IViewComponentResult> InvokeAsync()
|
|
{
|
|
if (_signInManager.IsSignedIn(HttpContext.User))
|
|
{
|
|
menuItems.Add(new AppMenuItem { id = "999", text = "Logout", parentId = "", url = "/Account/Logout" });
|
|
}
|
|
else
|
|
{
|
|
menuItems.Add(new AppMenuItem { id = "999", text = "Login", parentId = "", url = "/Account/Login" });
|
|
}
|
|
var model = menuItems;
|
|
ViewBag.menuitems = menuItems;
|
|
return await Task.FromResult((IViewComponentResult)View("MenuItems", model));
|
|
}
|
|
|
|
}
|
|
}
|