C
C#2y ago
Vinicius

❔ rename tuple

public async Task<(List<SalesReportEntity>, int totalSales)> GetAllSalesReportAsync(int companyId, int? SalesPage, int? Limitpage, DateTime? StartDate, DateTime? EndDate)
{
return (sales, sales.Count());
}
obs: I cut off some lines
public async Task<(List<SalesReportEntity>, int totalSales)> GetAllSalesReportAsync(int companyId, int? SalesPage, int? Limitpage, DateTime? StartDate, DateTime? EndDate)
{
return (sales, sales.Count());
}
obs: I cut off some lines
is returning item1: [{…}] item2: 1 How can I rename it to sales and totalSales
16 Replies
Angius
Angius2y ago
I'd probably just use a record here instead of a tuple But return (sales: sales, totalSales: sales.Count()) should work With the return type being Task<(List<SalesReportEntity> sales, int totalSales)>
sibber
sibber2y ago
this not necessary actually, if you specify the names in the return type
Vinicius
ViniciusOP2y ago
public async Task<(List<SalesReportEntity>allSales, int totalSales)> GetAllSalesReportAsync(){
return (allSales: sales, totalSales: sales.Count());
}
public async Task<(List<SalesReportEntity>allSales, int totalSales)> GetAllSalesReportAsync(){
return (allSales: sales, totalSales: sales.Count());
}
wont change :-:
Vinicius
ViniciusOP2y ago
MODiX
MODiX2y ago
Cyberrex#8052
REPL Result: Success
System.Text.Json.JsonSerializer.Serialize((allSales: 1, totalSales: 2), new JsonSerializerOptions { IncludeFields = true })
System.Text.Json.JsonSerializer.Serialize((allSales: 1, totalSales: 2), new JsonSerializerOptions { IncludeFields = true })
Result: string
{"Item1":1,"Item2":2}
{"Item1":1,"Item2":2}
Compile: 444.748ms | Execution: 52.984ms | React with ❌ to remove this embed.
sibber
sibber2y ago
huh
Angius
Angius2y ago
I guess STJ doesn't serialize named tuples Thankfully, solution is simple: just use a record
Vinicius
ViniciusOP2y ago
you right
Vinicius
ViniciusOP2y ago
Vinicius
ViniciusOP2y ago
return new SalesResume(sales, sales.Count());
Vinicius
ViniciusOP2y ago
idk if I did best way
Angius
Angius2y ago
I'd just keep the record next to the method tbh, no need to make a whole separate file for it But, sure, it works either way
Vinicius
ViniciusOP2y ago
Interface need to be typed as well
namespace Epilefinho.Domain.Repositories
{
public interface ISaleRepository
{

Task<SalesResume> GetAllSalesReportAsync(int idCompany, int? NumberPage, int? Limitpage, DateTime? StartDate, DateTime? EndDate);

}
}
namespace Epilefinho.Domain.Repositories
{
public interface ISaleRepository
{

Task<SalesResume> GetAllSalesReportAsync(int idCompany, int? NumberPage, int? Limitpage, DateTime? StartDate, DateTime? EndDate);

}
}
I'd prefer but I couldnt
Angius
Angius2y ago
Yeah, understandable
Vinicius
ViniciusOP2y ago
thanks
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server