public PartialViewResult _AuditReport(AuditSearchVM search) { List <AuditSearchVM> Data = new List <AuditSearchVM>(); var Result = UnitOfWork.AuditBL.AuditSearch(search) .Select(au => new AuditSearchVM { UserName = au.User?.FullName, AuditId = au.Id, Date = au.Date, ActionName = Enum.GetName(typeof(AuditActionType), au.ActionTypeId).ToString(), TableName = au.TableName, OldData = au.OldData, NewData = au.NewData }).ToList(); return(PartialView(Result)); }
public FileResult ExportAuditReport(AuditSearchVM search) { using (var stream = new MemoryStream()) try { var Result = UnitOfWork.AuditBL.AuditSearch(search); var SheetAudit = Result.Select(c => new AuditExport(c)).ToArray(); var CycelReport = Helper.GenerateDataTable(SheetAudit); using (var wb = new XLWorkbook()) { wb.Worksheets.Add(CycelReport, "AuditReport"); wb.SaveAs(stream); return(File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "AuditReport.xlsx")); } } catch (Exception e) { return(null); } }
public List <DataAudit> AuditSearch(AuditSearchVM search) { List <DataAudit> results = new List <DataAudit>(); try { var CurrentDate = DateTime.Now; var query = Context.DataAudit.Include(f => f.User) .AsQueryable(); if (search != null) { if (search.DepartmentIds?.Count > 0) { query = query.Where(c => search.DepartmentIds.Contains(c.User.DepartmentId)); } if (search.Users?.Count > 0) { query = query.Where(c => search.Users.Contains(c.UserId)); } if (search.StartDate != null) { DateTime StartDate = DateTime.ParseExact(search.StartDate, "dd/MM/yyyy HH:mm", null); query = query.Where(u => u.Date >= StartDate); } if (search.StartDate != null) { DateTime EndDate = DateTime.ParseExact(search.EndDate, "dd/MM/yyyy HH:mm", null); query = query.Where(u => u.Date <= EndDate); } if (search.Actions?.Count > 0) { query = query.Where(c => search.Actions.Contains(c.ActionTypeId)); } } results = query.OrderByDescending(au => au.Date).ToList(); } catch (Exception e) { } return(results); }
public ActionResult SearchPost(AuditSearchVM model, int page = 1) { // Iterate through form keys foreach (string Key in Request.Form.Keys) { // Test if Select button was clicked... if (Key.StartsWith("Search::SearchPost_")) { // Retrieve ID for entity which was selected Guid Value = Guid.Parse(Key.Substring(19)); // Store ID for Edit screen SessionManager.AuditCode = Value.ToString(); // Call out to Edit screen return(RedirectToAction("Edit", "Audit", new { code = Value })); } } // Return to the Screen return(View(model)); }
public ActionResult Search(int page = 1) { // Create service instance AdminServiceClient sc = new AdminServiceClient(); // Create model AuditSearchVM model = new AuditSearchVM(); try { AuditSearchVMDC response = sc.SearchAudit(CurrentUser, CurrentUser, appID, "", null, page, PageSize, true); // Close service communication sc.Close(); //Map response back to view model model.MatchList = Mapper.Map <IEnumerable <AuditSearchMatchDC>, List <AuditSearchMatchModel> >(response.MatchList); // Set paging values model.TotalRows = response.RecordCount; model.PageSize = SessionManager.PageSize; model.PageNumber = page; // Store the page number we were on SessionManager.AuditPageNumber = model.PageNumber; return(View(model)); } catch (Exception e) { // Handle the exception string message = ExceptionManager.HandleException(e, sc); model.Message = message; return(View(model)); } }