static public ELogisticsDriverIncident GetByID(string id) { using var context = new SMySQLContext(); ELogisticsDriverIncident eIncident = context.LogisticsDriverIncidents.SingleOrDefault(x => x.id == id); return(eIncident); }
//=====================================================GETS ABOVE===================================================== #region Save static public async Task <string> Save(ELogisticsDriverIncident eIncident) { try { eIncident.modificationDateUTC = DateTime.UtcNow; using (var context = new SMySQLContext()) { if (string.IsNullOrEmpty(eIncident.id)) { eIncident.id = Guid.NewGuid().ToString(); eIncident.creationDateUTC = eIncident.modificationDateUTC = DateTime.UtcNow; var e = await context.LogisticsDriverIncidents.AddAsync(eIncident); await context.SaveChangesAsync(); return(e.Entity.id); } else { var e = context.LogisticsDriverIncidents.Update(eIncident); await context.SaveChangesAsync(); return(e.Entity.id); } } } catch (DbUpdateException e) { Console.WriteLine(e.ToString()); throw; } }
static public async Task <bool> Remove(string id) { using (var context = new SMySQLContext()) { ELogisticsDriverIncident eCompanyProposal = context.LogisticsDriverIncidents.SingleOrDefault(x => x.id == id); if (eCompanyProposal == null) { return(false); } context.Remove(eCompanyProposal); await context.SaveChangesAsync(); return(true); } }
public async Task <IActionResult> Save([FromBody] ELogisticsDriverIncident eIncident) { var result = await SLogisticsDriversIncidents.Save(eIncident); return(Ok(result)); }