Ejemplo n.º 1
0
        private List <Branch> GetAllBranches()
        {
            // Get a list of branches from database
            List <Branch> branchList = branchContext.GetAllBranches();

            // Adding a select prompt at the first row of the branch list
            branchList.Insert(0, new Branch
            {
                BranchNo = 0,
                Address  = "--Select--"
            });
            return(branchList);
        }
        // GET: BranchController
        public ActionResult Index(int?id)
        {
            // Stop accessing the action if not logged in
            // or account not in the "Staff" role
            if ((HttpContext.Session.GetString("Role") == null) ||
                (HttpContext.Session.GetString("Role") != "Staff"))
            {
                return(RedirectToAction("Index", "Home"));
            }
            BranchViewModel branchVM = new BranchViewModel();

            branchVM.branchList = branchContext.GetAllBranches();
            // Check if BranchNo (id) presents in the query string
            if (id != null)
            {
                ViewData["selectedBranchNo"] = id.Value;
                // Get list of staff working in the branch
                branchVM.staffList = branchContext.GetBranchStaff(id.Value);
            }
            else
            {
                ViewData["selectedBranchNo"] = "";
            }
            return(View(branchVM));
        }