Exemplo n.º 1
0
        public async Task <Result <FileContent> > ParseUploadedFileAsync(string filePath)
        {
            return(await TryCatchExtension.ExecuteAndHandleErrorAsync(async() =>
            {
                await Task.Delay(1000);

                return Result.Success(ParseFile(filePath));
            },
                                                                      ex => new TryCatchExtensionResult <Result <FileContent> >
            {
                DefaultResult = Result.Failure <FileContent>($"Error message: {ex.Message}. Details:"),
                RethrowException = false
            }));
        }
Exemplo n.º 2
0
        public async Task <AuthenticateResponseDTO> AuthenticationAsync(AuthenticateRequestDTO dto)
        {
            AuthenticateResponseDTO authenticateResponse = null;

            await TryCatchExtension.ExecuteAndHandleErrorAsync(
                async() =>
            {
                var login = await _authenticationManagementRepository
                            .LoginRepository
                            .FindAsync <Employee>(x => x.UserName == dto.UserName && x.Password == dto.Password.GetString(), x => x.Employee);

                var jwtToken = await GenerateJwtTokenAsync(login, GenerateClaimsIdentity(login.UserName, login.Id));

                authenticateResponse = AuthenticateResponseDTO.Create(login.Id, login.UserName, login.Employee.RoleId, jwtToken, true);
            },
                ex =>
            {
                _proLogger.Error($"An error occurred while authenticating the user having username: {dto.UserName}. Error: {ex.Message}");

                return(false);
            });

            return(authenticateResponse);
        }