public IActionResult GetGarage(int id) { var garage = _garageService.GetGarage(id); var model = _mapper.Map <Garage>(garage); return(Ok(model)); }
public async Task <IActionResult> Edit(int id) { try { DateTime activationDate; var model = await _garageService.GetGarage(id); DateTime.TryParse(model.ActivationDate, out activationDate); model.RootUrl = BaseRootUrl; if (activationDate != null) { model.ActivationDate = activationDate.ToString("yyyy-MM-dd"); } model.BannerList = await _referenceService.GetBannerSelectListItem(); model.LanguageList = await _referenceService.GetLanguageSelectList(CurrentUser.GarageSetting.Language); model.DateFormatList = _referenceService.GetDateFormatSelectList(); model.BrandingLogo = $"{model.BrandingLogo}/{model.BrandingId}_logo.jpg"; return(View(model)); } catch (Exception ex) { ex.ToExceptionless().Submit(); return(BadRequest()); } }
private async Task <IEnumerable <UserViewModel> > GetUsers(int garageId = 0) { try { var result = new List <UserViewModel>(); var userList = _userIdentity.UserManager.Users.ToList(); var users = userList.Adapt <IEnumerable <UserViewModel> >(); foreach (var user in users) { IdentityUser identityUser = await _userIdentity.UserManager.FindByIdAsync(user.Id); IList <Claim> claims = await _userIdentity.UserManager.GetClaimsAsync(identityUser); IList <string> roles = await _userIdentity.UserManager.GetRolesAsync(identityUser); var garage = await _garageService.GetGarage(claims.Any(c => c.Type == "GarageId")?Convert.ToInt32(claims.FirstOrDefault(c => c.Type == "GarageId")?.Value) : 0); if (garageId == 0 || (garageId != 0 && garage.Id == garageId && !roles.Contains("SuperAdmin"))) { result.Add(new UserViewModel() { Id = user.Id, Email = user.Email, LockedOut = user.LockoutEnd != null, Roles = roles, Clients = claims.FirstOrDefault(c => c.Type == "Clients")?.Value.Split(",").ToList(), ClientsIdList = claims.Any(c => c.Type == "Clients") ? claims.FirstOrDefault(c => c.Type == "Clients")?.Value : string.Empty, FirstName = claims.Any(c => c.Type == "FirstName") ? claims.FirstOrDefault(c => c.Type == "FirstName")?.Value : string.Empty, LastName = claims.Any(c => c.Type == "LastName") ? claims.FirstOrDefault(c => c.Type == "LastName")?.Value : string.Empty, UserName = user.UserName, GarageId = claims.Any(c => c.Type == "GarageId") ? Convert.ToInt32(claims.FirstOrDefault(c => c.Type == "GarageId")?.Value) : 0, GarageName = garage?.Name, }); } } return(result); } catch (Exception ex) { ex.ToExceptionless().Submit(); return(null); } }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { //Get claims var identityUser = await _signInManager.UserManager.FindByEmailAsync(Input.Email); IList <Claim> claims = await _signInManager.UserManager.GetClaimsAsync(identityUser); //Get language in garage var defaultLanguage = "fr"; var garageId = claims.FirstOrDefault(p => p.Type.ToUpper() == "GARAGEID"); if (garageId != null) { var garage = await _garageService.GetGarage(Convert.ToInt32(garageId.Value)); if (garage != null) { defaultLanguage = garage.Language; } } _logger.LogInformation("User logged in."); return(LocalRedirect(UserHelper.GetStartUpUrl(defaultLanguage, returnUrl))); } if (result.RequiresTwoFactor) { return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe })); } if (result.IsLockedOut) { _logger.LogWarning("User account locked out."); return(RedirectToPage("./Lockout")); } else { Input = new InputModel() { Translation = new TranslationModel() { Message = _localizer["Message"], RememberMe = _localizer["RememberMe"], ConnectButton = _localizer["ConnectButton"], ForgotPassword = _localizer["ForgotPassword"], Email = _localizer["Email"], Password = _localizer["Password"], } }; ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(Page()); } } // If we got this far, something failed, redisplay form return(Page()); }