public int SaveAudit(int userId, string desc, AuditAction action) { context.Audit.Add(new Audit { AuditTime = DateTime.Now, Action = $"{action.ToString()} : {desc}", UserId = userId }); return(context.SaveChanges()); }
public AuditLog Build() { return(new AuditLog { Action = action.ToString(), Actioner = actioner, Changes = changes, Dttm = DateTime.Now, Type = type, Target = target }); }
internal void WriteXml(XmlWriter writer) { writer.WriteElementString("timestamp", InstantPattern.ExtendedIso.Format(Timestamp)); writer.WriteStartElement("app-id"); writer.WriteAttributeString("name", ApplicationName); writer.WriteValue(_applicationId.ToString()); writer.WriteEndElement(); writer.WriteStartElement("person-id"); writer.WriteAttributeString("name", PersonName); writer.WriteValue(_personId.ToString()); writer.WriteEndElement(); if (ImpersonatorId != null) { writer.WriteStartElement("impersonator-id"); if (!string.IsNullOrEmpty(ImpersonatorName)) { writer.WriteAttributeString("name", ImpersonatorName); } writer.WriteValue(ImpersonatorId.ToString()); writer.WriteEndElement(); } if (AccessAvenue != HealthServiceAuditAccessAvenue.Unknown) { writer.WriteElementString("access-avenue", AccessAvenue.ToString()); } if (AuditAction != HealthServiceAuditAction.Unknown) { writer.WriteElementString("audit-action", AuditAction.ToString()); } if (_masterAppId != Guid.Empty) { writer.WriteElementString("master-app-id", _masterAppId.ToString()); } }
public bool Validate(string token, string URL, AuditAction action) { try { var dataUsuario = new RepositoryUser().GetToken(token); var dataPermiso = GetAll(dataUsuario.ProfileID); var dataModulo = new RepositoryModule().GetURL(URL); bool AllowAccess = false; switch (action) { case AuditAction.Access: AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Access; break; case AuditAction.Read: AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Read; break; case AuditAction.Add: AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Add; break; case AuditAction.Update: AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Update; break; case AuditAction.Delete: AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Delete; break; case AuditAction.Export: AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Export; break; default: AllowAccess = false; break; } if (AllowAccess) { new BusinessAudit().Insert(new ModelViewAudit() { ModuleID = dataModulo.ModuleID, UserID = dataUsuario.UserID, Action = action.ToString() }); } return(AllowAccess); } catch { return(true); } }
private static void Validate(AuditAction action, string id, T before, T after) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id), "Cannot be null"); } if (after == default(T)) { throw new ArgumentNullException(nameof(after), $"Cannot be null when Audtion action is {action.ToString()}. Pass empty instance in case {AuditAction.Add.ToString()} is used."); } if (before == default(T)) { throw new ArgumentNullException(nameof(before), $"Cannot be null when Audtion action is {action.ToString()}. Pass empty instance in case {AuditAction.Delete.ToString()} is used."); } }