51 lines
987 B
C#
51 lines
987 B
C#
using Events.EF.Data.Postgres;
|
|
using Events.EF.Models;
|
|
|
|
namespace GraphQLServer.SetupGraphQL;
|
|
|
|
public partial class Mutations
|
|
{
|
|
public async Task<Event> AddEvent([Service] EventsContext ctx, EventInput input)
|
|
{
|
|
var item = new Event
|
|
{
|
|
Name = input.Name,
|
|
EventDate = input.EventDate
|
|
};
|
|
|
|
ctx.Events.Add(item);
|
|
await ctx.SaveChangesAsync();
|
|
|
|
return item;
|
|
}
|
|
|
|
public async Task<Event?> UpdateEvent([Service] EventsContext ctx, int id, EventInput input)
|
|
{
|
|
var item = await ctx.Events.FindAsync(id);
|
|
if (item is null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
item.Name = input.Name;
|
|
item.EventDate = input.EventDate;
|
|
await ctx.SaveChangesAsync();
|
|
|
|
return item;
|
|
}
|
|
|
|
public async Task<bool> DeleteEvent([Service] EventsContext ctx, int id)
|
|
{
|
|
var item = await ctx.Events.FindAsync(id);
|
|
if (item is null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
ctx.Events.Remove(item);
|
|
await ctx.SaveChangesAsync();
|
|
|
|
return true;
|
|
}
|
|
}
|