public async Task <IActionResult> Register(SignupRequest request, CancellationToken cancellationToken) { try { var apiResponse = await _authService.RegisterAsync(request, cancellationToken); if (apiResponse.Success) { await _mailService.SendEmailAsync(request.Email, "New user registration", "<p>New user" + DateTime.Now + "</p>", cancellationToken); return(Ok(apiResponse)); } else if (apiResponse.Errors[0].Code == StatusCodes.Status404NotFound) { return(NotFound(apiResponse)); } return(BadRequest(apiResponse)); } catch (Exception exception) { return(_actionResultMapper.Map(exception)); } }
public async Task <IActionResult> GetAllFastTransactions([FromQuery] int pageNumber = PagingConstants.DefaultPageNumber, [FromQuery] int pageSize = PagingConstants.DefaultPageSize, CancellationToken cancellationToken = default) { try { var apiResponse = await _fastTransactionsService.GetAllFastTransactionsAsync(pageNumber, pageSize, cancellationToken); if (apiResponse.Success) { return(Ok(apiResponse)); } else if (apiResponse.Errors[0].Code == StatusCodes.Status404NotFound) { return(NotFound(apiResponse)); } return(BadRequest(apiResponse)); } catch (Exception exception) { return(_actionResultMapper.Map(exception)); } }
public async Task <IActionResult> GetAllCities(CancellationToken cancellationToken = default) { try { var apiResponse = await _citiesService.GetAllCitiesAsync(cancellationToken); if (apiResponse.Success) { return(Ok(apiResponse)); } return(BadRequest(apiResponse)); } catch (Exception exception) { return(_actionResultMapper.Map(exception)); } }
public async Task <IActionResult> GetUsersInRole([FromQuery] string roleId, CancellationToken cancellationToken) { var apiResponse = new Response(); var role = await _roleManager.FindByIdAsync(roleId); if (role == null) { apiResponse.AddError(ExceptionCreator.CreateNotFoundError(nameof(role), $"Role id: {roleId} is not found")); return(NotFound(apiResponse)); } var userRoleList = new List <UserRoleResponse>(); try { foreach (var user in _userManager.Users) { var userRole = new UserRoleResponse() { UserId = user.Id, UserName = user.UserName }; if (await _userManager.IsInRoleAsync(user, role.Name)) { userRole.HasRole = true; } else { userRole.HasRole = false; } userRoleList.Add(userRole); } return(Ok(userRoleList)); } catch (Exception exception) { return(_actionResultMapper.Map(exception)); } }
public async Task <IActionResult> GetAllAddresses([FromQuery] int pageNumber = PagingConstants.DefaultPageNumber, [FromQuery] int pageSize = PagingConstants.DefaultPageSize, CancellationToken cancellationToken = default) { try { var apiResponse = await _addressService.GetAllAddressesAsync(pageNumber, pageSize, cancellationToken); if (apiResponse.Success) { return(Ok(apiResponse)); } return(BadRequest(apiResponse)); } catch (Exception exception) { return(_actionResultMapper.Map(exception)); } }
public async Task <IActionResult> GetAllCashTransactions([FromQuery] int pageNumber = PagingConstants.DefaultPageNumber, [FromQuery] int pageSize = PagingConstants.DefaultPageSize, CancellationToken cancellationToken = default) { try { var apiResponse = await _cashTransactionsService.GetAllCashTransactionsAsync(pageNumber, pageSize, cancellationToken); if (apiResponse.Success) { var pagedApiResponse = new PagedResponse <CashTransactionListResponse>(apiResponse.Data); return(Ok(pagedApiResponse)); } return(BadRequest(apiResponse)); } catch (Exception exception) { return(_actionResultMapper.Map(exception)); } }
public async Task <IActionResult> GetBankAccountsByCustomerId([FromRoute] int customerId, CancellationToken cancellationToken = default) { var user = await _userManager.GetUserAsync(User); var customer = await _customerService.GetCustomerByIdAsync(customerId, cancellationToken); var apiResponse = new Response(); if (customer == null) { apiResponse.AddError(ExceptionCreator.CreateNotFoundError(nameof(customer))); return(NotFound(apiResponse)); } if (user.Id != customer?.Data?.UserId) { apiResponse.AddError(ExceptionCreator.CreateForbiddenError(nameof(user), "user is not authorized to complete transaction")); return(Forbid()); } try { apiResponse = await _bankAccountService.GetBankAccountsByCustomerIdAsync(customerId, cancellationToken); if (apiResponse.Success) { return(Ok(apiResponse)); } else if (apiResponse.Errors[0].Code == StatusCodes.Status404NotFound) { return(NotFound(apiResponse)); } return(BadRequest(apiResponse)); } catch (Exception exception) { return(_actionResultMapper.Map(exception)); } }