public IActionResult Index() { try { ViewData[ViewDataKeys.HtmlPageNameReceivedFromApi] = "Home"; } catch (BasicWebAppException ex) { // Logging exception and showing UI message to the user. ExceptionProcessor.ProcessError(LoggingEvents.ReadItemsFailed, _logger, HttpContext, ex); } return(View()); }
public async Task <IActionResult> GetAll() { var usersViewModel = (IEnumerable <ApplicationUserViewModel>) new List <ApplicationUserViewModel>(); try { var usersContract = await _internalApiClient.GetApplicationUsers(); } catch (BasicWebAppException ex) { ExceptionProcessor.ProcessError(LoggingEvents.ReadItemsFailed, _logger, HttpContext, ex); } return(View("~/Views/Administration/Users/UserList.cshtml", usersViewModel)); }
public async Task<IActionResult> Details(Guid id) { TenantViewModel tenantViewModel = null; try { var tenant = await _internalApiClient.GetTenantByGuid(id); tenantViewModel = _mapper.Map<TenantViewModel>(tenant); } catch (BasicWebAppException ex) { ExceptionProcessor.ProcessError(LoggingEvents.ReadItemFailed, _logger, HttpContext, ex, id); } return View(tenantViewModel); }
public async Task <IActionResult> SignIn(SignInViewModel signInViewModel, string returnUrl = null) { ViewData[ViewDataNames.ReturnUrl] = returnUrl; if (!ModelState.IsValid) { _logger.LogWarning(LoggingEvents.SignInUserBadData, "SignIn user model is not valid. {ErrorMessages}", ModelState.GetModelStateErrorMessages()); return(View("~/Views/Account/SignIn.cshtml", signInViewModel)); } try { var signInRequestContract = _mapper.Map <SignInRequestContract>(signInViewModel); var signInResponseContract = await _internalApiClient.SignIn(signInRequestContract); var claims = new List <Claim> { new Claim(ClaimTypes.NameIdentifier, signInResponseContract.UserGuid.ToString()), new Claim(ClaimTypes.Name, signInViewModel.Username), new Claim(ClaimsCustomTypes.AccessToken, signInResponseContract.AccessToken) }; foreach (var userRole in signInResponseContract.UserRoles) { claims.Add(new Claim(ClaimTypes.Role, userRole)); } var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var claimsPrincipal = new ClaimsPrincipal(claimsIdentity); var authOptions = new AuthenticationProperties(); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal, authOptions); _logger.LogInformation(LoggingEvents.SignInUser, "Signing in user with GUID {Guid}.", signInResponseContract.UserGuid.ToString()); return(LocalRedirect(returnUrl)); } catch (BasicWebAppException ex) { ExceptionProcessor.ProcessError(LoggingEvents.SignInUserFailed, _logger, HttpContext, ex, signInViewModel.Username); } return(View("~/Views/Account/SignIn.cshtml", signInViewModel)); }
public async Task<IActionResult> Index(PaginationRequestViewModel paginationRequestViewModel) { var pagedTenantsViewModel = PagedResultsViewModel<TenantViewModel>.InitEmpty(); try { paginationRequestViewModel.PageSize ??= HttpContext.TryGetPageSizeFromCookie(); var pagination = _mapper.Map<Pagination>(paginationRequestViewModel); var pagedTenants = await _internalApiClient.GetTenants(pagination); pagedTenantsViewModel = _mapper.Map<PagedResultsViewModel<TenantViewModel>>(pagedTenants); _mapper.Map(pagination, pagedTenantsViewModel); } catch (BasicWebAppException ex) { ExceptionProcessor.ProcessError(LoggingEvents.ReadItemsFailed, _logger, HttpContext, ex); } return View(pagedTenantsViewModel); }
public async Task<IActionResult> Delete(Guid id, EditTenantViewModel editTenantViewModel) { if (!ModelState.IsValid) { _logger.LogWarning(LoggingEvents.DeleteItemBadData, "Delete tenant model is not valid. {ErrorMessages}", ModelState.GetModelStateErrorMessages()); return View(nameof(Update), editTenantViewModel); } try { await _internalApiClient.DeleteTenant(id); return RedirectToAction("index"); } catch (BasicWebAppException ex) { ExceptionProcessor.ProcessError(LoggingEvents.DeleteItemFailed, _logger, HttpContext, ex, id); } return View(nameof(Update), editTenantViewModel); }
public async Task<IActionResult> Create(NewTenantViewModel newTenantViewModel) { if (!ModelState.IsValid) { _logger.LogWarning(LoggingEvents.CreateItemBadData, "Empty tenant cannot be created. {ErrorMessages}", ModelState.GetModelStateErrorMessages()); return View(newTenantViewModel); } try { var newTenantApiContract = _mapper.Map<NewTenantContract>(newTenantViewModel); var newTenantGuid = await _internalApiClient.CreateNewTenant(newTenantApiContract); return RedirectToAction(nameof(Details), new { Id = newTenantGuid }); } catch (BasicWebAppException ex) { ExceptionProcessor.ProcessError(LoggingEvents.CreateItemFailed, _logger, HttpContext, ex, newTenantViewModel.Name); } return View(newTenantViewModel); }
public async Task<IActionResult> Update(Guid id, EditTenantViewModel editTenantViewModel) { if (!ModelState.IsValid) { _logger.LogWarning(LoggingEvents.UpdateItemBadData, "Edit tenant model is not valid. {ErrorMessages}", ModelState.GetModelStateErrorMessages()); return View(editTenantViewModel); } try { var editTenantContract = _mapper.Map<EditTenantContract>(editTenantViewModel); await _internalApiClient.EditTenant(id, editTenantContract); return RedirectToAction(nameof(Index)); } catch (BasicWebAppException ex) { ExceptionProcessor.ProcessError(LoggingEvents.UpdateItemFailed, _logger, HttpContext, ex, id); } return View(editTenantViewModel); }