public long UpdateRouting(TramoDto dto) { long result = default(long); try { TramoEntity tramoDb = _dbContext.TramoDataSet.FirstOrDefault(x => x.IdTramo == dto.IdTramo); if (tramoDb != null) { tramoDb.JsonRouting = dto.JsonRouting; _dbContext.SaveChanges(); } result = tramoDb.IdTramo; } catch (DbEntityValidationException ex) { foreach (var eve in ex.EntityValidationErrors) { foreach (var ve in eve.ValidationErrors) { _logger.Error("ServiceTramo.UpdateRouting", $"PropertyName: {ve.PropertyName} - ErrorMessage: {ve.ErrorMessage}", ex); } } } catch (Exception ex) { _logger.Error("ServiceTramo.CreateOrUpdate", ex.Message, ex); } return(result); }
public long CreateOrUpdate(TramoDto dto) { long result = default(long); try { using (var dbContext = new VialidadContext()) { TramoEntity tramoDb = dbContext.TramoDataSet.AsNoTracking().FirstOrDefault(x => x.IdProvincia == dto.IdProvincia && x.IdRuta == dto.IdRuta && x.TramoNormalizado.ToUpper() == dto.TramoNormalizado.ToUpper()); if (tramoDb == null) { tramoDb = MapDtoToEntity.Map(dto); tramoDb.FechaAlta = DateTime.Now; tramoDb.Activo = false; dbContext.TramoDataSet.Add(tramoDb); } else { tramoDb.IdCalzada = dto.IdCalzada; tramoDb.Detalle = dto.Detalle; tramoDb.Observaciones = dto.Observaciones; tramoDb.FechaActualizacion = dto.FechaActualizacion; tramoDb.TramoDesnormalizado = dto.TramoDesnormalizado; var exist = dbContext.Set <TramoEntity>().Find(tramoDb.IdTramo); if (exist != null) { dbContext.Entry <TramoEntity>(exist).CurrentValues.SetValues(tramoDb); } } dbContext.SaveChanges(); result = tramoDb.IdTramo; } } catch (DbEntityValidationException ex) { foreach (var eve in ex.EntityValidationErrors) { foreach (var ve in eve.ValidationErrors) { _logger.Error("ServiceTramo.CreateOrUpdate", $"PropertyName: {ve.PropertyName} - ErrorMessage: {ve.ErrorMessage}", ex); } } } catch (Exception ex) { _logger.Error("ServiceTramo.CreateOrUpdate", ex.Message, ex); } return(result); }
public static TramoEntity Map(TramoDto entidadDto) { var entity = new TramoEntity(); entity.IdTramo = entidadDto.IdTramo; entity.IdProvincia = entidadDto.IdProvincia; entity.IdRuta = entidadDto.IdRuta; entity.IdCalzada = entidadDto.IdCalzada; entity.TramoNormalizado = entidadDto.TramoNormalizado; entity.TramoDesnormalizado = entidadDto.TramoDesnormalizado; entity.Coordenadas = entidadDto.Coordenadas; entity.Detalle = entidadDto.Detalle; entity.Observaciones = entidadDto.Observaciones; entity.FechaActualizacion = entidadDto.FechaActualizacion; entity.Orden = entidadDto.Orden; return(entity); }
public TramoDto GetByCoordinates(string coordinates) { TramoDto result = null; try { TramoEntity tramo = _dbContext.TramoDataSet .OrderByDescending(x => x.FechaActualizacion) .ThenBy(x => x.Orden) .FirstOrDefault(x => x.Coordenadas == coordinates && x.Activo); if (tramo != null) { result = MapEntityToDto.Map(tramo); } } catch (Exception ex) { _logger.Error("ServiceTramo.GetByCoordinates", ex.Message, ex); } return(result); }