public async Task <List <Dictionary <string, object> > > Get(string id, LogViewFilter filter) { List <Log> logs = new List <Log>(); if (filter.Id) { Log find = await _logs.Find <Log>(log => log.Id == id).FirstOrDefaultAsync(); if (find != null) { logs.Add(find); } } if (filter.UserId) { List <Log> found = await _logs.Find(log => log.UserId == id).ToListAsync(); if (found.Count != 0) { logs.AddRange(found); } } if (filter.DocumentId) { List <Log> found = await _logs.Find(log => log.DocumentId == id).ToListAsync(); if (found.Count != 0) { logs.AddRange(found); } } if (filter.Document) { List <Log> found = await _logs.Find(log => log.Document.Contains(id)).ToListAsync(); if (found.Count != 0) { logs.AddRange(found); } } List <Dictionary <string, object> > convertedLogs = new List <Dictionary <string, object> >(); foreach (Log log in logs) { Dictionary <string, object> convertedLog = new Dictionary <string, object>(); Dictionary <string, object> convertedDocument = new Dictionary <string, object>(); if (log.Document != null) { convertedDocument = JsonConvert.DeserializeObject <Dictionary <string, object> >(log.Document); } convertedLog["logId"] = log.Id; convertedLog["userId"] = log.UserId; convertedLog["utc"] = log.TimestampUtc; convertedLog["message"] = log.Message; convertedLog["collection"] = log.Collection; convertedLog["documentId"] = log.DocumentId; convertedLog["document"] = convertedDocument.Count == 0 ? null : convertedDocument; convertedLogs.Add(convertedLog); } return(convertedLogs); }
public async Task <ActionResult <List <Dictionary <string, object> > > > Get([FromHeader] string authToken, string id, [FromQuery] LogViewFilter filters) { if (!await _authenticationService.CheckAccess(authToken, "logView")) { return(Unauthorized()); } List <Dictionary <string, object> > logs = await _logViewService.Get(id, filters); return(logs); }