public async Task <IActionResult> EditUserPermissionsAsync(NsModelUser.DetailsViewModel model)
        {
            IdentityUser _User = await __UserManager.FindByIdAsync(model.UserClaims.UserID);

            if (_User == null)
            {
                return(RedirectToAction("DetailsView", "User", new { Area = "Admin", uid = model.UserClaims.UserID, errorMessage = $"{GlobalConstants.ERROR_ACTION_PREFIX} find User." }));
            }

            IList <Claim> _Claims = await __UserManager.GetClaimsAsync(_User);

            IdentityResult _Result = await __UserManager.RemoveClaimsAsync(_User, _Claims);

            if (!_Result.Succeeded)
            {
                return(RedirectToAction("DetailsView", "User", new { Area = "Admin", uid = model.UserClaims.UserID, errorMessage = $"{GlobalConstants.ERROR_ACTION_PREFIX} update User Permissions." }));
            }

            _Result = await __UserManager.AddClaimsAsync(_User,
                                                         model.UserClaims.Claims.Select(c => new Claim(c.ClaimType, c.IsSelected ? "true" : "false")));

            if (!_Result.Succeeded)
            {
                return(RedirectToAction("DetailsView", "User", new { Area = "Admin", uid = model.UserClaims.UserID, errorMessage = $"{GlobalConstants.ERROR_ACTION_PREFIX} update User Permissions." }));
            }

            return(RedirectToAction("DetailsView", "User", new { Area = "Admin", uid = model.UserClaims.UserID, successMessage = $"{GlobalConstants.SUCCESS_ACTION_PREFIX} updated User Permissions." }));
        }
        public async Task <IActionResult> DetailsModalAsync(Guid uid)
        {
            IdentityUser _User = await __UserManager.FindByIdAsync(uid.ToString());

            if (_User == null)
            {
                return(Json(new { success = $"{GlobalConstants.ERROR_ACTION_PREFIX} find {ENTITY_NAME}" }));
            }

            NsModelUser.DetailsViewModel _Model = new NsModelUser.DetailsViewModel
            {
                User  = _User,
                Loans = __Mapper.Map <IList <Loan.Models.LoanViewModel> >(await __LoanManager.GetByLoaneeAsync(_User.Email)),
                Roles = await __UserManager.GetRolesAsync(_User)
            };

            return(PartialView("_DetailsModal", _Model));
        }
        public async Task <IActionResult> DetailsViewAsync(Guid uid, string successMessage, string errorMessage)
        {
            if (!string.IsNullOrWhiteSpace(successMessage))
            {
                ViewData["SuccessMessage"] = successMessage;
            }

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                ViewData["ErrorMessage"] = errorMessage;
            }

            IdentityUser _User = await __UserManager.FindByIdAsync(uid.ToString());

            if (_User == null)
            {
                return(RedirectToAction("Index", "User", new { Area = "Admin", errorMessage = $"User does not exist" }));
            }

            NsModelUser.DetailsViewModel _Model = new NsModelUser.DetailsViewModel
            {
                User  = _User,
                Roles = await __UserManager.GetRolesAsync(_User),
            };

            foreach (LoanResponse loan in await __LoanManager.GetByLoaneeAsync(_User.Email))
            {
                Loan.Models.LoanViewModel _LoanViewModel = __Mapper.Map <Loan.Models.LoanViewModel>(loan);

                IList <Guid> _EquipmentUIDs = (await __LoanEquipmentManager.GetAsync(loan.UID)).Select(x => x.EquipmentUID).ToList();
                if (_EquipmentUIDs != null && _EquipmentUIDs.Count > 0)
                {
                    _LoanViewModel.EquipmentList = __Mapper.Map <IList <Equipment.Models.EquipmentViewModel> >((await __EquipmentManager.GetAsync(_EquipmentUIDs)).Equipments);
                }

                _Model.Loans.Add(_LoanViewModel);
            }

            IList <Claim> _ExistingClains = await __UserManager.GetClaimsAsync(_User);

            _Model.UserClaims = new NsModelPermission.UserClaimsViewModel
            {
                UserID = uid.ToString()
            };

            foreach (Claim claim in ClaimsStore.AllClaims)
            {
                UserClaim _UserClaim = new UserClaim
                {
                    ClaimType  = claim.Type,
                    ClaimValue = claim.Value
                };

                if (_ExistingClains.Any(c => c.Type == claim.Type && c.Value == "true"))
                {
                    _UserClaim.IsSelected = true;
                }

                _Model.UserClaims.Claims.Add(_UserClaim);
            }

            return(View("Details", _Model));
        }