public override LogDto GetById(Guid Id)
 {
     using (UnitOfMongo op = new UnitOfMongo())
     {
         NoSQLLogEntity entity = op.Query <NoSQLLogEntity>().Where(x => x.Id.Equals(Id)).FirstOrDefault();
         return(ConvertEntityToDto(entity));
     }
 }
 public override List <LogDto> GetAll()
 {
     using (UnitOfMongo op = new UnitOfMongo())
     {
         List <NoSQLLogEntity> entity = op.Query <NoSQLLogEntity>().ToList();
         return(ConvertEntityListToDtoList(entity));
     }
 }
 public override AppDto GetById(Guid Id)
 {
     using (UnitOfMongo op = new UnitOfMongo())
     {
         return(op.Query <NoSQLLogEntity>().Where(x => x.AppId.Equals(Id)).Select(x => new AppDto {
             Id = x.AppId, Name = x.AppName
         }).FirstOrDefault());
     }
 }
 public override List <AppDto> GetAll()
 {
     using (UnitOfMongo op = new UnitOfMongo())
     {
         return(op.Query <NoSQLLogEntity>().Select(x => new AppDto {
             Id = x.AppId, Name = x.AppName
         }).Distinct().ToList());
     }
 }
        public List <LogDto> GetLogsByAppId(Guid AppId)
        {
            List <LogDto> result = new List <LogDto>();

            using (UnitOfMongo op = new UnitOfMongo())
            {
                result = ConvertEntityListToDtoList(op.Query <NoSQLLogEntity>().Where(x => x.AppId.Equals(AppId)).Take(10000).OrderBy(x => x.LogDate).ToList());
            }
            return(result);
        }
 public override void Delete(LogDto dto)
 {
     using (UnitOfMongo op = new UnitOfMongo())
     {
         NoSQLLogEntity entity = op.Query <NoSQLLogEntity>().Where(x => x.Id.Equals(dto.Id)).FirstOrDefault();
         if (entity != null)
         {
             op.Delete(entity);
         }
     }
 }
        public List <LogReportDto> GetLogsReport()
        {
            List <LogReportDto> result = new List <LogReportDto>();

            using (UnitOfMongo op = new UnitOfMongo())
            {
                List <AppDto> apps = (new NoSQLAppRepository()).GetAll();
                result = op.Query <NoSQLLogEntity>().GroupBy(x => new { x.AppId, x.AppName, x.Level }).Select(y => new LogReportDto {
                    Id = y.Key.AppId, AppName = y.Key.AppName, Level = y.Key.Level, Count = y.Count()
                }).ToList();
            }
            return(result);
        }
 public override void Delete(AppDto dto)
 {
     using (UnitOfMongo op = new UnitOfMongo())
     {
         List <NoSQLLogEntity> entity = op.Query <NoSQLLogEntity>().Where(x => x.AppId.Equals(dto.Id)).ToList();
         if (entity != null && entity.Count > 0)
         {
             foreach (NoSQLLogEntity log in entity)
             {
                 op.Delete(log);
             }
         }
     }
 }
 public override void Save(AppDto dto)
 {
     using (UnitOfMongo op = new UnitOfMongo())
     {
         List <NoSQLLogEntity> logs = op.Query <NoSQLLogEntity>().Where(x => x.AppId.Equals(dto.Id)).ToList();
         if (logs != null && logs.Count > 0)
         {
             foreach (NoSQLLogEntity entity in logs)
             {
                 entity.AppName = dto.Name;
                 op.SaveOrUpdate(entity);
             }
         }
     }
 }
 public override void Save(LogDto dto)
 {
     using (UnitOfMongo op = new UnitOfMongo())
     {
         NoSQLLogEntity entity = op.Query <NoSQLLogEntity>().Where(x => x.Id.Equals(dto.Id)).FirstOrDefault();
         if (entity == null)
         {
             entity = new NoSQLLogEntity();
         }
         entity.AppId   = dto.App.Id;
         entity.AppName = dto.App.Name;
         entity.Level   = dto.Level;
         entity.LogDate = dto.LogDate;
         entity.Message = dto.Message;
         op.SaveOrUpdate(entity);
     }
 }
 private int CountLogs(Guid?SelectedApp, string TextToSearch)
 {
     using (UnitOfMongo op = new UnitOfMongo())
     {
         op.BeginTransaction();
         IEnumerable <NoSQLLogEntity> query = op.Query <NoSQLLogEntity>();
         if (!string.IsNullOrEmpty(TextToSearch))
         {
             query = query.Where(x => x.Message.Contains(TextToSearch));
         }
         if (SelectedApp != null)
         {
             query = query.Where(x => x.AppId.Equals(SelectedApp));
         }
         return(query.Count());
     }
 }
        public IPagedList <LogDto> Search(Guid?SelectedApp, string TextToSearch, int PageNum, int SizePage)
        {
            using (UnitOfMongo op = new UnitOfMongo())
            {
                IQueryable <NoSQLLogEntity> query = op.Query <NoSQLLogEntity>();
                if (!string.IsNullOrEmpty(TextToSearch))
                {
                    query = query.Where(x => x.Message.ToLower().Contains(TextToSearch.ToLower()));
                }
                if (SelectedApp != null)
                {
                    query = query.Where(x => x.AppId.Equals(SelectedApp));
                }

                query = query.Skip((PageNum - 1) * SizePage);
                query = query.Take(SizePage);
                List <NoSQLLogEntity> entity = query.ToList();
                List <LogDto>         dto    = ConvertEntityListToDtoList(entity);

                return(new StaticPagedList <LogDto>(dto.AsEnumerable <LogDto>(), PageNum, SizePage, CountLogs(SelectedApp, TextToSearch)));
            }
        }