rcnespoli
rcnespoli
CC#
Created by rcnespoli on 4/26/2024 in #help
JSON deserialize
But I will try
12 replies
CC#
Created by rcnespoli on 4/26/2024 in #help
JSON deserialize
it's will be hard
12 replies
CC#
Created by rcnespoli on 4/26/2024 in #help
JSON deserialize
yes
12 replies
CC#
Created by rcnespoli on 4/26/2024 in #help
JSON deserialize
but it's the same structure
12 replies
CC#
Created by rcnespoli on 4/26/2024 in #help
JSON deserialize
of course I just omit the real value
12 replies
CC#
Created by rcnespoli on 4/26/2024 in #help
JSON deserialize
yes
12 replies
CC#
Created by rcnespoli on 3/28/2024 in #help
List extension
Thank you
7 replies
CC#
Created by rcnespoli on 3/28/2024 in #help
List extension
oh nice! Is there some doc to I see more details about generics?
7 replies
CC#
Created by rcnespoli on 2/19/2024 in #help
How can I decode Avro Message that have an embedded schema and after the message content?
I tried using Apache Avro and Hadoop, but didn't worked
26 replies
CC#
Created by rcnespoli on 2/19/2024 in #help
How can I decode Avro Message that have an embedded schema and after the message content?
thanks
26 replies
CC#
Created by rcnespoli on 2/19/2024 in #help
How can I decode Avro Message that have an embedded schema and after the message content?
I will take a look
26 replies
CC#
Created by rcnespoli on 10/15/2023 in #help
✅ Dapper relation tables
?
4 replies
CC#
Created by rcnespoli on 10/15/2023 in #help
✅ Dapper relation tables
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Dapper;
using Npgsql;
using Tiss.Domain.Repositories;
using Tiss.Domain.Users.Models;
using Tiss.Infra.Repositories.User.Entities;
using Tiss.Infra.Repositories.User.Queries;
using Tiss.Shared.EnvironmentVariables;

namespace Tiss.Infra.Repositories.User;

public class PostgresqlUserRepository : IUserRepository
{
private readonly NpgsqlConnection _connection;
private readonly UserTableQueries _queries = new();

public PostgresqlUserRepository(ApplicationEnvVars applicationEnvVars)
{
_connection = new NpgsqlConnection(applicationEnvVars.PostgreSqlEnvVars.ConnectionString);
_connection.Open();
}

public async Task<UserModel?> GetUserByTaxId(string taxId)
{
try
{
var dynamicParameters = new DynamicParameters();
dynamicParameters.Add("TaxId", taxId);
var queryResult = await _connection.QueryAsync<UserEntity>(_queries.GetUserByTaxId(), dynamicParameters);
var userModel = ToDomain(queryResult);
return userModel;
}
catch (Exception e)
{
// TODO: add logger;
Console.WriteLine(e);
throw;
}
}

private UserModel ToDomain(IEnumerable<UserEntity> userEntities) =>
new()
{
Name = userEntities.First().Name,
Password = userEntities.First().Password,
Email = userEntities.First().Email,
TaxId = userEntities.First().TaxId,
RelatedCompanies = userEntities.Select(v => v.CompanyId).ToList()
};
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Dapper;
using Npgsql;
using Tiss.Domain.Repositories;
using Tiss.Domain.Users.Models;
using Tiss.Infra.Repositories.User.Entities;
using Tiss.Infra.Repositories.User.Queries;
using Tiss.Shared.EnvironmentVariables;

namespace Tiss.Infra.Repositories.User;

public class PostgresqlUserRepository : IUserRepository
{
private readonly NpgsqlConnection _connection;
private readonly UserTableQueries _queries = new();

public PostgresqlUserRepository(ApplicationEnvVars applicationEnvVars)
{
_connection = new NpgsqlConnection(applicationEnvVars.PostgreSqlEnvVars.ConnectionString);
_connection.Open();
}

public async Task<UserModel?> GetUserByTaxId(string taxId)
{
try
{
var dynamicParameters = new DynamicParameters();
dynamicParameters.Add("TaxId", taxId);
var queryResult = await _connection.QueryAsync<UserEntity>(_queries.GetUserByTaxId(), dynamicParameters);
var userModel = ToDomain(queryResult);
return userModel;
}
catch (Exception e)
{
// TODO: add logger;
Console.WriteLine(e);
throw;
}
}

private UserModel ToDomain(IEnumerable<UserEntity> userEntities) =>
new()
{
Name = userEntities.First().Name,
Password = userEntities.First().Password,
Email = userEntities.First().Email,
TaxId = userEntities.First().TaxId,
RelatedCompanies = userEntities.Select(v => v.CompanyId).ToList()
};
}
Is this correct?
4 replies
CC#
Created by rcnespoli on 7/19/2023 in #help
❔ Builder with generics
Yeah.. i changed the approach.. I appreciate your time, thank you
9 replies
CC#
Created by rcnespoli on 7/19/2023 in #help
❔ Builder with generics
Yeah, I think it's not good use object or something casting
9 replies
CC#
Created by rcnespoli on 7/19/2023 in #help
❔ Builder with generics
So in this case how can I deal with this?
9 replies
CC#
Created by rcnespoli on 7/19/2023 in #help
❔ How can I create a command handler factory, with this structure that I have
I want a class that create commandHandler by MyEnum values
4 replies
CC#
Created by rcnespoli on 3/26/2023 in #help
❔ Could I create two folder using dotnet new webapi?
Ok, thank you 🙂
6 replies