blazor-calendar/BlazorApp/Data/CalendarService.cs

27 lines
775 B
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);
}
}
}