public ActionResult Index() { var store = new Microsoft.AspNet.Identity.EntityFramework.UserStore<NetCafeWeb.Models.ApplicationUser>(new NetCafeWeb.Models.ApplicationDbContext()); var manager = new Microsoft.AspNet.Identity.UserManager<NetCafeWeb.Models.ApplicationUser>(store); var a = manager.IsInRoleAsync(User.Identity.GetUserId(), "Admin"); bool isAdmin = a.Result; IRepository<User> userRepository = new UserRepository(); IEnumerable<User> users = userRepository.List; ViewBag.users = users.Cast<User>().ToList(); IRepository<PC> pcRepository = new PCRepository(); IEnumerable<PC> pcs = pcRepository.List; ViewBag.pcs = pcs.Cast<PC>().ToList(); if (isAdmin) { //show het order IRepository<Order> repository = new OrderRepository(); IEnumerable<Order> order = repository.List; ViewBag.orders = order.Cast<Order>().ToList(); //FormsAuthentication.SetAuthCookie("asd", false); return View(); } else //La supervisor { //Lay supervior user String supervisorName = User.Identity.Name; //Lay supervior id UserRepository repo = new UserRepository(); NetCafeRepository netRepo = new NetCafeRepository(); OrderRepository orderRepo = new OrderRepository(); int supervisorId = repo.getIDByUsername(supervisorName); //Lay netcafe id int netID = netRepo.getNetCafeIDByName(supervisorId); //hien thi order cua netcafe id List<Order> orders = orderRepo.getOrderByNetCafe(netID); ViewBag.orders = orders; } return View(); }
public ActionResult Create(int? id) { //Lay login user name String username = User.Identity.GetUserName(); UserRepository userRepo = new UserRepository(); int userId = userRepo.getIDByUsername(username); ViewBag.userId = userId; //Lay user id IRepository<NetCafe> repository = new NetCafeRepository(); if (id != null) { PCRepository repo = new PCRepository(); List<PC> pcs = repo.findAvailable(id.Value); NetCafe selectedNetcafe = repository.findById(id.Value); ViewBag.selectedNetCafe = selectedNetcafe; ViewBag.pcs = pcs; } IEnumerable<NetCafe> iNetCafes = repository.List; List<NetCafe> netcafes = iNetCafes.Cast<NetCafe>().ToList(); ViewBag.netcafes = netcafes; return View(); }
public List<NetCafe> GetManageNet(string username) { NetCafeRepository NetRepo = new NetCafeRepository(); UserRepository UserRepo = new UserRepository(); List<NetCafe> ManageNet = new List<NetCafe>(); int SuperID = UserRepo.getIDByUsername(username); if (SuperID.ToString() == null) { return null; } else { try { ManageNet = NetRepo.findBySuID(SuperID); } catch (Exception e) { e.GetHashCode(); return null; } return ManageNet; } }