Пример #1
0
        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();
        }