コード例 #1
0
        public async Task <IResponseItem <IUser> > GetAllUsersAsync()
        {
            IResponseItem <IUser> response   = new ResponseItem <IUser>();
            DbConnection          connection = null;
            DbDataReader          reader;

            IUser user;

            try
            {
                string commandText = @"SELECT * FROM USERS";
                using var command = this.GetCommand(commandText, CommandType.Text);

                (connection, reader) = await this.ExecuteReaderAsync(command);

                while (await reader.ReadAsync())
                {
                    user = new User
                    {
                        Id   = DBNullExt.ToValue <string>(reader["Id"]),
                        Name = DBNullExt.ToValue <string>(reader["NAME"]),

                        FirstName      = DBNullExt.ToValue <string>(reader["FIRSTNAME"]),
                        lastName       = DBNullExt.ToValue <string>(reader["LASTNAME"]),
                        Email          = DBNullExt.ToValue <string>(reader["EMAIL"]),
                        CreateDate     = DBNullExt.ToValue <DateTime>(reader["CREATEDATE"]),
                        ModifyDate     = DBNullExt.ToValue <DateTime>(reader["MODIFYDATE"]),
                        LastSignInDate = DBNullExt.ToValue <DateTime>(reader["LASTSIGNINDATE"]),
                        ConnectionId   = DBNullExt.ToValue <string>(reader["CONNECTIONID"]),
                        //Token = DBNullExt.ToValue<string>(reader["TOKEN"]),
                        IsLive   = DBNullExt.ToValue <int>(reader["ISLIVE"]),
                        IsActive = DBNullExt.ToValue <int>(reader["ISACTIVE"])
                    };

                    response.Items.Add(user);
                }

                await reader.CloseAsync();
            }
            catch (Exception ex)
            {
                throw new DatabaseException(ex.Message, ex);
            }
            finally
            {
                if (connection?.State == ConnectionState.Open)
                {
                    await connection.CloseAsync();
                }
            }

            return(response);
        }
コード例 #2
0
        public async Task <IConnectRootResponse <IUser> > GetUserAsync(string email)
        {
            IConnectRootResponse <IUser> response = new ConnectRootResponse <IUser>();
            DbConnection connection = null;
            DbDataReader reader;

            IUser user = null;

            try
            {
                string commandText = @"SELECT * FROM USERS WHERE EMAIL=@EMAIL";
                using var command = this.GetCommand(commandText, CommandType.Text);
                this.CreateParameter(command, "@EMAIL", email, DbType.String);

                (connection, reader) = await this.ExecuteReaderAsync(command);

                if (await reader.ReadAsync())
                {
                    user = new User
                    {
                        Id   = DBNullExt.ToValue <string>(reader["Id"]),
                        Name = DBNullExt.ToValue <string>(reader["NAME"]),

                        FirstName      = DBNullExt.ToValue <string>(reader["FIRSTNAME"]),
                        lastName       = DBNullExt.ToValue <string>(reader["LASTNAME"]),
                        Email          = DBNullExt.ToValue <string>(reader["EMAIL"]),
                        CreateDate     = DBNullExt.ToValue <DateTime>(reader["CREATEDATE"]),
                        ModifyDate     = DBNullExt.ToValue <DateTime>(reader["MODIFYDATE"]),
                        LastSignInDate = DBNullExt.ToValue <DateTime>(reader["LASTSIGNINDATE"]),
                        ConnectionId   = DBNullExt.ToValue <string>(reader["CONNECTIONID"]),
                        //Token = DBNullExt.ToValue<string>(reader["TOKEN"]),
                        IsLive   = DBNullExt.ToValue <int>(reader["ISLIVE"]),
                        IsActive = DBNullExt.ToValue <int>(reader["ISACTIVE"])
                    };
                }
                await reader.CloseAsync();

                if (user != null)
                {
                    response.Status       = ConnectConstants.Success;
                    response.Message      = ConnectResponseCodes.CP024_MESSAGE;
                    response.ResponseCode = ConnectResponseCodes.CP024;
                    response.ResponseData = user;
                }
                else
                {
                    response.Status       = ConnectConstants.Failed;
                    response.Message      = ConnectResponseCodes.CP023_MESSAGE;
                    response.ResponseCode = ConnectResponseCodes.CP023;
                }
            }
            catch (Exception ex)
            {
                throw new DatabaseException(ex.Message, ex);
            }
            finally
            {
                if (connection?.State == ConnectionState.Open)
                {
                    await connection.CloseAsync();
                }
            }

            return(response);
        }