Ejemplo n.º 1
0
        public async Task <IEnumerable <Movement> > GetMovementsByAccount(Guid userId, Guid accountId, int page, int size)
        {
            var sql = new StringBuilder();

            sql.Append($"SELECT Id, Value, Description, Category, [Type], AccountId, UserId, CreatedOn, UpdatedOn");
            sql.Append($" FROM {table} WHERE AccountId = @accountId AND UserId = @userId");
            sql.Append($" ORDER BY CreatedOn DESC");
            sql.Append($" OFFSET @offset ROWS FETCH NEXT @next ROWS ONLY");

            await using var connection = new SqlConnection(_configuration.GetConnectionString("DatabaseConnection"));
            connection.Open();

            var dictionary = new Dictionary <string, object>
            {
                { "@userId", userId },
                { "@accountId", accountId },
                { "@offset", (page - 1) * size },
                { "@next", size }
            };

            var parameters = new DynamicParameters(dictionary);

            var movement = await connection.QueryAsync <FS.Data.Entities.Movement>(sql.ToString(), parameters);

            return(MovementEntityToMovementeDomainMapper.MapFrom(movement));
        }
Ejemplo n.º 2
0
        public async Task <Movement> Get(Guid id)
        {
            var sql = new StringBuilder();

            sql.Append($"SELECT Id, Value, Description, Category, [Type], AccountId, UserId, CreatedOn, UpdatedOn");
            sql.Append($" FROM {table} WHERE ID = @id");

            await using var connection = new SqlConnection(_configuration.GetConnectionString("DatabaseConnection"));
            connection.Open();

            var dictionary = new Dictionary <string, object>
            {
                { "@id", id }
            };

            var parameters = new DynamicParameters(dictionary);

            var movement = await connection.QueryFirstAsync <FS.Data.Entities.Movement>(sql.ToString(), parameters);

            return(MovementEntityToMovementeDomainMapper.MapFrom(movement));
        }