public ActionResult ReportPDF(int periodID, int term) { var period = db.ValidationPeriods.Where(e => e.PeriodID.Equals(periodID) && e.Term.Equals(term)).FirstOrDefault(); if (period != null) { ReportsMasterViewModel viewModel = new ReportsMasterViewModel() { Scholarships = db.Scholarships.ToList(), UserProfiles = db.UserProfiles.Where(e => e.AspNetUser.ValidationPeriod.PeriodID.Equals(period.PeriodID)).ToList(), ValidationPeriods = db.ValidationPeriods.ToList(), ValidationRequests = db.ValidationRequests.Where(e => e.PeriodID.Equals(period.PeriodID)).ToList() }; var userID = User.Identity.GetUserId(); AspNetUser user = db.AspNetUsers.Where(e => e.Id.Equals(userID)).FirstOrDefault(); ViewBag.PeriodID = periodID; string message = string.Format("Generated report for {0} to {1}, term {2}", period.AcademicYearStart, period.AcademicYearEnd, term); AuditActions.AddMessage(db, message, userID); return(new Rotativa.PartialViewAsPdf("_Report", viewModel)); } else { return(Content("<html>Report cannot be generated</html>")); } }
/// <summary> /// Checks if the current user needs auditing for the action specified /// </summary> /// <param name="action">Action.</param> /// <returns>true if the user needs auditing, otherwise false</returns> public static bool CheckIfNeedsAuditing(AuditActions auditActionID) { AuditActionCollection auditActions = GetAuditActions(); if (auditActions != null && auditActions.Count > 0) { // create an ActionRight entity, and forcing the PK value, to avoid fetching it from the database. AuditActionEntity auditAction = new AuditActionEntity(); auditAction.Fields[(int)AuditActionFieldIndex.AuditActionID].ForcedCurrentValueWrite((int)auditActionID); auditAction.IsNew = false; return(auditActions.Contains(auditAction)); } return(false); }
/// <summary> /// Checks if the current user needs auditing for the action specified /// </summary> /// <param name="session">The session the method works on</param> /// <param name="auditActionID">the id of the audit action to take</param> /// <returns>true if the user needs auditing, otherwise false</returns> public static bool CheckIfNeedsAuditing(this ISession session, AuditActions auditActionID) { var auditActions = session.GetAuditActions(); return(auditActions != null && auditActions.Length > 0 && auditActions.Contains((int)auditActionID)); }
public AuditEntity Audit(AuditActions action, string tenantId, string companyId, Type model, string key, object previousObject, object currentObject) { #if DEBUG #warning [WARNING!!!] Audit trail must exclude byte or binary fields that might contain large data. Remove this warning after implemented. #endif var comparer = new CompareLogic(); comparer.Config.MaxDifferences = 99; comparer.Config.IgnoreObjectTypes = true; comparer.Config.TypesToIgnore = new List <Type> { typeof(byte), typeof(byte[]) }; // Test this with binaries and remove pragma warnings above. // comparer.Config.TypesToIgnore.AddRange(new Type[] { // typeof(byte), // typeof(byte[]) // }); comparer.Config.MembersToIgnore.AddRange(new string[] { "ConcurrencyStamp", "ConcurrencyTimeStamp", "DateCreated", "DateModified", "DateDeleted" }); var result = comparer.Compare(previousObject, currentObject); var deltas = new List <AuditDelta>(); if (result.AreEqual && action == AuditActions.Update) { return(null); } foreach (var change in result.Differences) { var delta = new AuditDelta(); delta.PropertyName = change.PropertyName; delta.PreviousValue = change.Object1Value; delta.CurrentValue = change.Object2Value; deltas.Add(delta); } // if(typeof(ITenantEntity<Guid, TKey>).IsAssignableFrom(model)) // { // tenantId = ((ITenantEntity<Guid, TKey>) model).TenantId.ToString(); // } // if(typeof(ICompanyEntity<Guid, Guid, TKey>).IsAssignableFrom(model)) // Just default to GUID for company id for now. // { // companyId = ((ICompanyEntity<Guid, Guid, TKey>) model).CompanyId.ToString(); // } return(new AuditEntity { Action = action.ToString(), Source = "Audit Manager", TimeStamp = DateTime.UtcNow, Model = model.Name, Namespace = model.Namespace, TenantId = tenantId, CompanyId = companyId, Key = key, PreviousValue = JsonConvert.SerializeObject(previousObject), CurrentValue = JsonConvert.SerializeObject(currentObject), Changes = JsonConvert.SerializeObject(deltas) }); }