/// <summary> /// Add Audit Log Entries /// </summary> /// <param name="_Action"> Action happened </param> /// <param name="ctlr">Object of Current Controller, just use "this" keyword</param> public static void AddAuditLog(string AuditLogShortDesc, string AuditLogLongDesc, Controller ctlr = null) { long?userID = null; if (ctlr != null && ctlr.User != null) { if (ctlr.User.Identity.IsAuthenticated) { using (DBEntities db = new DBEntities()) { var user = db.Users.FirstOrDefault(m => m.EmailAddress == ctlr.User.Identity.Name); userID = user.UserID; } } } AuditLogs log = new AuditLogs() { LogDate = DateTime.Now, AuditLogShortDesc = AuditLogShortDesc, AuditLogLongDesc = AuditLogLongDesc, UserID = userID }; if (log.UserID == null) { //If UserID is null it means this log is generated by Automation so add to AuditLog History Table in MVF_AuditHistory Database var auditLogRepository = new AuditLogRepository(); auditLogRepository.AddAuditLog_ToHistory(log); } else { var auditLogRepository = new AuditLogRepository(); auditLogRepository.AddAuditLog(log); } }