WebApi + ClientApp, GraphQL, Reflection
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using Events.EF.Data.MSSQL;
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user