Exemple #1
0
        public void Error(string origen, string message = "", Exception ex = null, [CallerMemberName] string sourceMember = "", [CallerLineNumber] int lineNumber = 0, [CallerFilePath] string filePath = "", bool global = false, bool generateMessage = true)
        {
            var log = new LogEntity();

            log.TipoLog   = "E";
            log.Fecha     = DateTime.UtcNow;
            log.UtcOffSet = _UtcOffSet;

            if (ex != null)
            {
                log.Origen      = global ? origen : string.Format(_SourceFormat, sourceMember, lineNumber, filePath.GetResumePath());
                log.Descripcion = (!generateMessage && string.IsNullOrWhiteSpace(ex.Message)) ? message : ex.GetDescription();
                log.Detalle     = ex.GetDetail();
                log.StackTrace  = ex.GetStackTrace();
                log.Source      = ex.Source;
                log.TargetSite  = ex.TargetSite != null ? ex.TargetSite.Name : string.Empty;
            }
            else
            {
                log.Origen      = string.Format(_SourceFormat, sourceMember, lineNumber, filePath);
                log.Descripcion = message;
            }

            using (var dbContext = new VialidadContext())
            {
                dbContext.LogDataSet.Add(log);
                dbContext.SaveChanges();
            }
        }
        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);
        }
Exemple #3
0
        public void Warning(string origen, string message, [CallerMemberName] string sourceMember = "", [CallerLineNumber] int lineNumber = 0, [CallerFilePath] string filePath = "")
        {
            var log = new LogEntity();

            log.TipoLog     = "W";
            log.Origen      = string.Format(_SourceFormat, sourceMember, lineNumber, filePath.GetResumePath());
            log.Fecha       = DateTime.UtcNow;
            log.UtcOffSet   = _UtcOffSet;
            log.Descripcion = message;

            using (var dbContext = new VialidadContext())
            {
                dbContext.LogDataSet.Add(log);
                dbContext.SaveChanges();
            }
        }
 public ServiceBase()
 {
     _dbContext = new VialidadContext();
     _logger    = LoggerFactory.GetInstance();
 }