Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="log"></param>
        /// <returns></returns>
        public int Update(ErrorLogModel log)
        {
            if (log == null)
            {
                return(CoreConstants.NullLogResponse);
            }

            if (string.IsNullOrWhiteSpace(log.Id))
            {
                return(CoreConstants.EmptyLogIdResponse);
            }

            var emptystring = Guid.Empty.ToString();

            if (log.Id == emptystring)
            {
                return(CoreConstants.EmptyGuidLogIdResponse);
            }

            emptystring = emptystring.Replace("-", string.Empty);

            if (log.Id == emptystring)
            {
                return(CoreConstants.EmptyGuidLogIdResponse);
            }

            var result = -1;

            var entity = default(ErrorLogEntity);

            using (var repo = new ErrorLogRepository <ErrorLogEntity>())
            {
                entity = repo.FirstOrDefault(q => q.Id == log.Id);
                if (entity != null && entity != default(ErrorLogEntity))
                {
                    SimpleMapper.MapTo(log, entity);
                    repo.Update(entity);
                    result = repo.SaveChanges();
                }
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="log"></param>
        /// <returns></returns>
        public string Save(ErrorLogModel log)
        {
            if (log == null)
            {
#if DEBUG
                log = new ErrorLogModel();
#else
                return("null");
#endif
            }

            var logId     = log?.Id ?? string.Empty;
            var emptyGuid = Guid.Empty.ToString();

            if (string.IsNullOrWhiteSpace(logId) ||
                logId == emptyGuid ||
                logId == emptyGuid.Replace("-", string.Empty))
            {
                log.Id = Guid.NewGuid().ToString();
            }

            if (!log.LogTime.HasValue)
            {
                log.LogTime = DateTime.Now;
                log.LogTimeUnixTimestamp = log.LogTime.Value.Ticks;
            }

            log.CreatedOn = DateTime.Now;
            log.CreatedOnUnixTimestamp = log.CreatedOn.Ticks;
            var entity = SimpleMapper.Map <ErrorLogModel, ErrorLogEntity>(log);

            using (var repo = new ErrorLogRepository <ErrorLogEntity>())
            {
                repo.Add(entity);
                repo.SaveChanges();
            }

            return(entity.Id);
        }