Skip to content

Instantly share code, notes, and snippets.

View andrebaltieri's full-sized avatar
🏠
Working from home

Andre Baltieri andrebaltieri

🏠
Working from home
View GitHub Profile
using Refit;
using FinaFlow.Core.Entities;
namespace FinaFlow.Services;
public interface ICategoryService
{
[Post("/v1/categories/")]
Task CreateAsync([Body] Category category);
using RestSharp;
using FinaFlow.Core.Entities;
namespace FinaFlow.Services;
public class CategoryService
{
private readonly RestClient _client;
public CategoryService(IHttpClientFactory httpClientFactory)
using System.Net.Http.Json;
using FinaFlow.Core.Entities;
namespace FinaFlow.Services;
public class CategoryService(
IHttpClientFactory httpClientFactory)
{
public async Task CreateAsync(
Category category)
// Exemplo de variáveis
let a = 10;
let b: u32 = 20;
let c = a + b;
var minhaLista = new List<Food> {
new Food { Type = "Mineira"},
new Food { Type = "Italiana"},
new Food { Type = "Japonesa"}
};
for (int i = 0; i <= minhaLista.Count; i++)
{
var item = minhaLista[i];
Console.WriteLine(item.Type);
// Lista de strings
var minhaLista = new List<string> { "arroz", "feijão", "banana" };
// Quero iterar sobre esta lista
// Utilizando for, precisamos de um contador (No caso i)
// Sabendo que os arrays no C# começam do ZERO...
// Então é uma boa prática começar i como zero
// Contamos até que i seja menor que 3 (Total de itens da lista)
for (int i = 0; i < 3; i++)
{
"final_space": true,
"console_title": true,
"console_title_style": "folder",
"blocks": [
{
"type": "prompt",
"alignment": "left",
"horizontal_offset": 0,
"vertical_offset": 0,
var orders = new List<Order>
{
new("Order 1 -10 itens", GenerateOrderLines(9)),
new("Order 2 +10 itens ", GenerateOrderLines(12)),
new("Order 3 +10 itens", GenerateOrderLines(18)),
new("Order 4 +10 itens", GenerateOrderLines(22))
};
List<OrderLine> GenerateOrderLines(int quantity)
{
@andrebaltieri
andrebaltieri / modelstate.cs
Created October 27, 2021 15:52
ASP.NET ModelState
builder.Services.AddControllers()
.ConfigureApiBehaviorOptions(options =>
{
options.SuppressModelStateInvalidFilter = true;
});
public static class DateTimeExtension
{
public static bool IsWeekend(this DateTime date) => date.DayOfWeek is DayOfWeek.Saturday or DayOfWeek.Sunday;
public static bool IsHoliday(this DateTime date, IEnumerable<DateTime> holidays) => holidays.Any(x => x == date);
public static DateTime Normalize(this DateTime date, IEnumerable<DateTime> holidays)
{
while (date.IsHoliday(holidays) || date.IsWeekend())
{