public async Task <Guid> Create(Models.PersoPJ_BG perPJBg) { try { var context = CreateContext(); var created = new Data.PersoPJ_BG { Id = perPJBg.Id, PJId = perPJBg.PJId, Version = perPJBg.Version, TitreBg = perPJBg.TitreBg, BG_Corps = perPJBg.BG_Corps, }; var enr = await context ._PersoPJ_BG .AddAsync(created); await context.SaveChangesAsync(); return(enr.Entity.Id); } catch (DbUpdateException e) { Console.WriteLine(e.Message); return(perPJBg.Id); } }
public async Task Delete(Models.PersoPJ_BG perPJBg) { try { var context = CreateContext(); var toDelete = await context._PersoPJ_BG.FindAsync(perPJBg.Id); if (toDelete != null) { context._PersoPJ_BG.Remove(toDelete); await context.SaveChangesAsync(); } } catch (DbUpdateException e) { Console.WriteLine(e.Message); } }
public async Task Update(Models.PersoPJ_BG perPJBg) { try { var context = CreateContext(); var toUpdate = await context._PersoPJ_BG.FindAsync(perPJBg.Id); if (toUpdate != null) { toUpdate.Id = perPJBg.Id; toUpdate.PJId = perPJBg.PJId; toUpdate.Version = perPJBg.Version; toUpdate.TitreBg = perPJBg.TitreBg; toUpdate.BG_Corps = perPJBg.BG_Corps; await context.SaveChangesAsync(); } } catch (DbUpdateException e) { Console.WriteLine(e.Message); } }