/// <summary>
        /// Returns an identity based on the given email address
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <param name="hashPassword"></param>
        /// <returns></returns>
        public ClaimsIdentity GetIdentity(string email, ClaimsIdentity identity) //<-true
        {
            email = (email ?? string.Empty).ToLowerInvariant();


            // Get user by email/password
            var user = _userService.Get(email);

            if (user == null || !user.IsActive)
            {
                identity.AddClaim(new Claim(ClaimTypes.Email, email));
                identity.AddClaim(new Claim(ClaimTypes.Role, UserRoles.Guest.ToString()));

                return(identity);
            }

            return(CreateIdentity(user, identity));
        }
        public ActionResult Edit(long?userid)
        {
            if (userid != null)
            {
                var user = _userService.Get(userid.Value);

                var model = new EditModel(user);

                long firstmanagerid  = user.Manager;
                long?secondmanagerid = user.SecondManager;

                long departmentid = user.Department;

                //Bereidt de managerdropdown voor
                var           managers     = _manService.GetAll();
                List <object> listmanagers = new List <object>();
                foreach (var item in managers)
                {
                    listmanagers.Add(new
                    {
                        ManagerID = item.ManagerID,
                        Name      = item.ApplicationUser.FirstName + " " + item.ApplicationUser.LastName
                    });
                }
                var dropdownmanagers = new SelectList(listmanagers, "ManagerID", "Name");

                //Dropdown van de afdeling voorbereiden
                var           departments     = _depService.GetAllDepartments();
                List <object> listdepartments = new List <object>();
                foreach (var item in departments)
                {
                    listdepartments.Add(new
                    {
                        DepartmentID = item.DepartmentID,
                        Name         = item.DepartmentName
                    });
                }


                //Vul de huidige afdeling in
                model.SelectedDepartment = departmentid;
                var dropdowndepartments = new SelectList(listdepartments, "DepartmentID", "Name", model.SelectedDepartment);
                model.Departments = dropdowndepartments;


                //Vindt de geselecteerde manager, vult deze in het model.
                model.SelectedFirstManager = firstmanagerid;
                var dropdownfirstmanager = new SelectList(listmanagers, "ManagerID", "Name", model.SelectedFirstManager);
                model.FirstManagers = dropdownfirstmanager;


                if (secondmanagerid != null)
                {
                    model.SelectedSecondManager = secondmanagerid.Value;
                    var dropdownsecondmanager = new SelectList(listmanagers, "ManagerID", "Name", model.SelectedSecondManager);
                    model.SecondManagers = dropdownsecondmanager;
                }
                else
                {
                    var dropdownsecondmanager = new SelectList(listmanagers, "ManagerID", "Name");
                    model.SecondManagers = dropdownsecondmanager;
                }

                model.IsMedewerker = true;

                //Zorgt ervoor dat de vorige pagina wordt onthouden, zodat wanneer er op annuleren wordt gedrukt. We terug kunnen naar dezelfde pagina.
                model.previousUrl = Request.UrlReferrer;

                return(View(model));
            }

            return(RedirectToAction("IndexHR", "User"));
        }
        public ActionResult ManagerDashboard()
        {
            var model = new ManagerModel();

            long userid = SecurityHelper.GetUserId();

            if (userid == 0)
            {
                return(RedirectToAction("NoAccess", "Account"));
            }

            long managerid = _manService.GetManageridByUserID(userid);

            model.IsAvailable = _manService.IsAvailable(managerid);

            List <long> list = new List <long>();

            list = _manService.Listwithavailablemanager().Select(p => p.ManagerID).ToList();

            model.FirstManagerNotAvailable = _vacreqService.FirstManagerHasVacation(managerid, list);

            //Verlofdagen over
            int TotalMinutes = _mutvacService.GetMinutesVacationByID(userid);

            model.Time = (TotalMinutes / 60).ToString() + " uur" + " (" + (TotalMinutes / 480).ToString() + " dagen" + " & " + ((TotalMinutes % 480) / 60).ToString() + " uur) " + ((TotalMinutes % 480) % 60).ToString() + " minuten";


            //Verlofaanvragen
            //Verlof van vandaag
            model.VacationRequestToday = _vacreqService.GetCurrentVacation(userid).ToPagedList(model.Page, model.PageSize);

            //Openstaande verlofverzoeken van onderstaande medewerkers van de manager
            model.VacationRequestAssess = _vacreqService.GetVacationRequestInTreatmentByManagerBy3(managerid).ToPagedList(model.Page, model.PageSize);
            //Openstaande verlofverzoeken van onderstaande medewerkers van de manager die als laatste zijn toegevoegd
            model.VacationRequestAssessNew = _vacreqService.GetVacationRequestInTreatmentNewByManagerBy3(managerid).ToPagedList(model.Page, model.PageSize);

            //Alle verlofaanvragen
            model.VacationRequest = _vacreqService.GetAll(userid).ToPagedList(model.Page, model.PageSize);

            //Geaccepteerde verlofaanvragen
            model.VacationRequestAccepted = _vacreqService.GetAcceptedVacationBy3(userid).ToPagedList(model.Page, model.PageSize);

            //Afgewezen verlofaanvragen
            model.VacationRequestRejected = _vacreqService.GetRejectedVacationBy3(userid).ToPagedList(model.Page, model.PageSize);

            //Verlofaanvragen in behandeling
            model.VacationRequestInTreatment = _vacreqService.GetInTreatmentVacationBy3(userid).ToPagedList(model.Page, model.PageSize);

            //Verlofaanvragen die voorgesteld zijn
            model.VacationRequestProposition = _vacreqService.GetPropositionVacationBy3(userid).ToPagedList(model.Page, model.PageSize);

            //Gebruikersgegevens
            model.currentuser = _userService.GetById(userid).ToPagedList(model.Page, model.PageSize);


            //Bijbehorende managerid van de huidige gebruiker
            long userhasmanagerid = _userService.Get(userid).Manager;
            //Manager voor de huidige gebruiker
            long manageruserid = _manService.GetUserIDByManagerID(userhasmanagerid);

            model.currentmanager = _userService.GetById(manageruserid).ToPagedList(model.Page, model.PageSize);


            return(View(model));
        }