public async Task <Guid> Create(Models.Social soci) { try { var context = CreateContext(); int Sc, Sd; Sd = soci.StatutDemCtct switch { StatuDemContact.envoyee => Sd = 0, StatuDemContact.approuvee => Sd = 1, StatuDemContact.blacklist => Sd = 3, _ => Sc = 0, }; Sc = soci.StatutCtct switch { StatuContact.connecte => Sc = 0, StatuContact.occupe => Sc = 1, StatuContact.nepasdéranger => Sc = 2, StatuContact.deretourbientot => Sc = 3, StatuContact.absent => Sc = 4, StatuContact.deconnecte => Sc = 5, _ => Sc = 0, }; var created = new Data.Social { Id = soci.Id, UserId = soci.UserId, ContactId = soci.ContactId, StatutDemContact = Sd, StatutContact = Sc, }; var enr = await context ._Social .AddAsync(created); await context.SaveChangesAsync(); return(enr.Entity.Id); } catch (DbUpdateException e) { Console.WriteLine(e.Message); return(soci.Id); } }
public async Task Delete(Models.Social soci) { try { var context = CreateContext(); var toDelete = await context._Social.FindAsync(soci.Id); if (toDelete != null) { context._Social.Remove(toDelete); await context.SaveChangesAsync(); } } catch (DbUpdateException e) { Console.WriteLine(e.Message); } }
public async Task Update(Models.Social soci) { try { var context = CreateContext(); var toUpdate = await context._Social.FindAsync(soci.Id); int Sc, Sd; Sd = soci.StatutDemCtct switch { StatuDemContact.envoyee => Sd = 0, StatuDemContact.approuvee => Sd = 1, StatuDemContact.blacklist => Sd = 3, _ => Sc = 0, }; Sc = soci.StatutCtct switch { StatuContact.connecte => Sc = 0, StatuContact.occupe => Sc = 1, StatuContact.nepasdéranger => Sc = 2, StatuContact.deretourbientot => Sc = 3, StatuContact.absent => Sc = 4, StatuContact.deconnecte => Sc = 5, _ => Sc = 0, }; if (toUpdate != null) { toUpdate.Id = soci.Id; toUpdate.UserId = soci.UserId; toUpdate.ContactId = soci.ContactId; toUpdate.StatutDemContact = Sd; toUpdate.StatutContact = Sc; await context.SaveChangesAsync(); } } catch (DbUpdateException e) { Console.WriteLine(e.Message); } }