Initial commit

This commit is contained in:
Mark J Price 2022-03-13 16:17:01 +00:00
parent 1d9d051759
commit 9656378279
557 changed files with 182300 additions and 0 deletions

View file

@ -0,0 +1,11 @@
namespace Packt.Shared;
public interface INorthwindService
{
Task<List<Customer>> GetCustomersAsync();
Task<List<Customer>> GetCustomersAsync(string country);
Task<Customer?> GetCustomerAsync(string id);
Task<Customer> CreateCustomerAsync(Customer c);
Task<Customer> UpdateCustomerAsync(Customer c);
Task DeleteCustomerAsync(string id);
}

View file

@ -0,0 +1,59 @@
using Microsoft.EntityFrameworkCore;
namespace Packt.Shared;
public class NorthwindService : INorthwindService
{
private readonly NorthwindContext db;
public NorthwindService(NorthwindContext db)
{
this.db = db;
}
public Task<List<Customer>> GetCustomersAsync()
{
return db.Customers.ToListAsync();
}
public Task<List<Customer>> GetCustomersAsync(string country)
{
return db.Customers.Where(c => c.Country == country).ToListAsync();
}
public Task<Customer?> GetCustomerAsync(string id)
{
return db.Customers.FirstOrDefaultAsync
(c => c.CustomerId == id);
}
public Task<Customer> CreateCustomerAsync(Customer c)
{
db.Customers.Add(c);
db.SaveChangesAsync();
return Task.FromResult(c);
}
public Task<Customer> UpdateCustomerAsync(Customer c)
{
db.Entry(c).State = EntityState.Modified;
db.SaveChangesAsync();
return Task.FromResult(c);
}
public Task DeleteCustomerAsync(string id)
{
Customer? customer = db.Customers.FirstOrDefaultAsync
(c => c.CustomerId == id).Result;
if (customer == null)
{
return Task.CompletedTask;
}
else
{
db.Customers.Remove(customer);
return db.SaveChangesAsync();
}
}
}

View file

@ -0,0 +1,13 @@
namespace Northwind.BlazorServer.Data
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

View file

@ -0,0 +1,20 @@
namespace Northwind.BlazorServer.Data
{
public class WeatherForecastService
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
{
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
}).ToArray());
}
}
}