This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# API de Usuários | |
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.4-buster-slim AS base | |
WORKDIR /app | |
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster as build | |
WORKDIR /src | |
COPY ["src/BuildingBlocks/NucleoCompartilhado/NucleoCompartilhado.csproj", "BuildingBlocks/NucleoCompartilhado/"] | |
COPY ["src/Servicos/Usuarios/Usuarios.csproj", "Servicos/Usuarios/"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var comprasPorMesECliente = Compras.GroupBy(compra => compra.Data.Month).Select(gp => new | |
{ | |
Mes = _dtFormat.GetMonthName(gp.Key), | |
TotalComprasMes = gp.Sum(c => c.Valor), | |
MaiorCompraMes = gp.Max(c => c.Valor), | |
QtdComprasMes = gp.Count(), | |
ComprasPorCliente = gp.GroupBy(c => c.Cliente).Select(g => new | |
{ | |
Cliente = g.Key, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IEnumerable<IGrouping<int, Compra>> grupos | |
= Compras.GroupBy(compra => compra.Pagamento.Month); // Como deve ser agrupado | |
foreach(var grupo in grupos) // Coleção de grupos | |
{ | |
WriteLine($"Compras pagas no mês de {_dtFormat.GetMonthName(grupo.Key)}"); // Chave do agrupamento | |
foreach(var elemento in grupo) // Compras do grupo => IGrouping<int, Compra> | |
{ | |
WriteLine($"\t{elemento.ToString()}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Apenas clientes com mais de uma compra | |
var aggComFiltro = grupos.Where(gp => gp.Count() > 1).Select(gp => new | |
{ | |
Cliente = gp.Key, | |
PiorCompra = gp.Where(c => c.Valor > 150).Min(x => x.Valor) | |
// Apenas compras acima de 150 | |
}); | |
foreach(var elemento in aggComFiltro) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var agg = grupos.Select(gp => new | |
{ | |
Cliente = gp.Key, | |
QuantidadeCompras = gp.Count(), | |
MelhorCompra = gp.Max(x => x.Valor), | |
PiorCompra = gp.Min(x => x.Valor), | |
TotalCompras = gp.Sum(x => x.Valor) | |
}); | |
foreach(var elemento in agg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IEnumerable<IGrouping<string, Compra>> grupos | |
= Compras.GroupBy(x => x.Cliente); // Como deve ser agrupado | |
foreach(var grupo in grupos) // Coleção de grupos | |
{ | |
WriteLine($"Compras de {grupo.Key}"); | |
foreach(var compra in grupo) // Compras do grupo => IGrouping<string, Compra> | |
{ | |
WriteLine($"\t {compra.Valor:n2}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Compra | |
{ | |
public string Cliente { get; set; } | |
public decimal Valor { get; set; } | |
public DateTime Data { get; set; } | |
public override string ToString() => $"{Cliente}, com valor de {Valor:n2} em {Data:dd/MM}"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EventosRepository | |
{ | |
public Evento[] ObterEventos() | |
{ | |
var eventos = Connection.Query<Evento>("Select * From Eventos Limit X, Y"); | |
ComporRelacionados(eventos); | |
return eventos; | |
} | |
private void ComporRelacionados(Evento[] eventos) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EventosRepository | |
{ | |
public Evento[] ObterEventos() | |
{ | |
var eventos = Connection.Query<Evento>("Select * From Eventos Limit X, Y"); | |
ComporRelacionados(eventos); | |
return eventos; | |
} | |
private void ComporRelacionados(Evento[] eventos) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<T> MeuWhere<T>(this IEnumerable<T> src, Func<T, bool> predicate) | |
{ | |
foreach(var item in src) | |
if (predicate(item)) | |
yield return item; | |
} |
NewerOlder