Пример #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);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="oid"></param>
        /// <returns></returns>
        public ErrorLogModel GetById(string oid)
        {
            var result = default(ErrorLogModel);

            if (string.IsNullOrWhiteSpace(oid) ||
                oid == Guid.Empty.ToString() ||
                oid == Guid.Empty.ToString().Replace("-", string.Empty))
            {
                return(result);
            }

            ErrorLogEntity entity = null;

            using (var repo = new ErrorLogRepository <ErrorLogEntity>())
            {
                entity = repo
                         .FirstOrDefault(q => q.Id == oid, asNoTracking: true);
            }

            result = SimpleMapper.Map <ErrorLogEntity, ErrorLogModel>(entity);
            return(result);
        }