Example #1
0
        public async Task <LogInDto> LogInUser(string user, string password)
        {
            LogInDto      objUser = null;
            SqlDataReader reader  = null;

            using (SqlCommand oCommand = await base.GetCommandAsync())
            {
                try
                {
                    oCommand.CommandType = CommandType.Text;
                    oCommand.CommandText = @"SELECT * FROM usuarios WHERE mail = @user and contraseƱa = @password";

                    oCommand.AddParameter("user", DbType.String, user);
                    oCommand.AddParameter("password", DbType.String, password);

                    IAsyncResult asyncResult = ExecuteAsync(oCommand, "LogInUser");
                    reader = oCommand.EndExecuteReader(asyncResult);

                    while (await reader.ReadAsync())
                    {
                        objUser = ModelBuilderHelper.BuildUserData(reader);
                    }
                    return(objUser);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, GetType().Name + "." + MethodBase.GetCurrentMethod().Name);
                    throw new AggregateException(_classFullName + ".LogInUser(string user, string password)", ex);
                }
                finally
                {
                    if (reader != null && !reader.IsClosed)
                    {
                        reader.Close();
                    }
                    if (!TransactionOpened())
                    {
                        base.CloseCommand();
                    }
                }
            }
        }