2021-07-03 12:19:53 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace BlazorApp.Data
|
|
|
|
|
{
|
|
|
|
|
public class CalendarService
|
|
|
|
|
{
|
|
|
|
|
public static async Task<List<Calendar>> GetCalendars()
|
|
|
|
|
{
|
|
|
|
|
await using var context = new MyContext();
|
|
|
|
|
return await context.Calendars.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<Calendar> GetCalendarById(int id)
|
|
|
|
|
{
|
|
|
|
|
await using var context = new MyContext();
|
|
|
|
|
return await context.Calendars.FindAsync(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task CreateCalendar(Calendar calendar)
|
|
|
|
|
{
|
|
|
|
|
await using var context = new MyContext();
|
|
|
|
|
await context.Calendars.AddAsync(calendar);
|
2021-07-04 10:16:51 +00:00
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task DeleteCalendar(Calendar calendar)
|
|
|
|
|
{
|
|
|
|
|
await using var context = new MyContext();
|
|
|
|
|
context.Calendars.Remove(calendar);
|
|
|
|
|
await context.SaveChangesAsync();
|
2021-07-03 12:19:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|