public async Task <Guid> Create(Models.PNJ peunj) { try { var context = CreateContext(); var created = new Data.PNJ { Id = peunj.Id, NomPNJ = peunj.NomPNJ, DescrptPNJ = peunj.DescrptPNJ, DescrptCostume = peunj.DescrptCostume, DescrptAttitude = peunj.DescrptAttitude, }; var enr = await context ._PNJ .AddAsync(created); await context.SaveChangesAsync(); return(enr.Entity.Id); } catch (DbUpdateException e) { Console.WriteLine(e.Message); return(peunj.Id); } }
public async Task Delete(Models.PNJ peunj) { try { var context = CreateContext(); var toDelete = await context._PNJ.FindAsync(peunj.Id); if (toDelete != null) { context._PNJ.Remove(toDelete); await context.SaveChangesAsync(); } } catch (DbUpdateException e) { Console.WriteLine(e.Message); } }
public async Task Update(Models.PNJ peunj) { try { var context = CreateContext(); var toUpdate = await context._PNJ.FindAsync(peunj.Id); if (toUpdate != null) { toUpdate.Id = peunj.Id; toUpdate.NomPNJ = peunj.NomPNJ; toUpdate.DescrptPNJ = peunj.DescrptPNJ; toUpdate.DescrptCostume = peunj.DescrptCostume; toUpdate.DescrptAttitude = peunj.DescrptAttitude; await context.SaveChangesAsync(); } } catch (DbUpdateException e) { Console.WriteLine(e.Message); } }