blazor-calendar/BlazorApp/Data/CalendarService.cs

35 lines
1.0 KiB
C#

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);
await context.SaveChangesAsync();
}
public static async Task DeleteCalendar(Calendar calendar)
{
await using var context = new MyContext();
context.Calendars.Remove(calendar);
await context.SaveChangesAsync();
}
}
}