public async Task DeleteAsync(int freightTypeID) { FreightType freightType = null; Stopwatch timespan = Stopwatch.StartNew(); if (db.TransportTypes.Any(r => r.FreightTypeID == freightTypeID)) { throw new ValidationException("Existen Tipos de Transportes asociados a este Tipo de Carga"); } try { freightType = await db.FreightTypes.FindAsync(freightTypeID); db.FreightTypes.Remove(freightType); await db.SaveChangesAsync(); timespan.Stop(); log.TraceApi("SQL Database", "FreightTypeRepository.DeleteAsync", timespan.Elapsed, "freightTypeID={0}", freightTypeID); } catch (Exception e) { log.Error(e, "Error in FreightTypeRepository.DeleteAsync(freightTypeID={0})", freightTypeID); throw; } }
public async Task CreateAsync(FreightType freightTypeToAdd) { Stopwatch timespan = Stopwatch.StartNew(); try { db.FreightTypes.Add(freightTypeToAdd); await db.SaveChangesAsync(); timespan.Stop(); log.TraceApi("SQL Database", "FreightTypeRepository.CreateAsync", timespan.Elapsed, "freightTypeToAdd={0}", freightTypeToAdd); } catch (Exception e) { log.Error(e, "Error in FreightTypeRepository.CreateAsync(freightTypeToAdd={0})", freightTypeToAdd); throw; } }
public async Task UpdateAsync(FreightType freightTypeToSave) { Stopwatch timespan = Stopwatch.StartNew(); try { db.Entry(freightTypeToSave).State = EntityState.Modified; await db.SaveChangesAsync(); timespan.Stop(); log.TraceApi("SQL Database", "FreightTypeRepository.UpdateAsync", timespan.Elapsed, "freightTypeToSave={0}", freightTypeToSave); } catch (Exception e) { log.Error(e, "Error in FreightTypeRepository.UpdateAsync(freightTypeToSave={0})", freightTypeToSave); throw; } }