public static IList <AuditLogRecord> GetLogs(ISession session, Payer payer, bool showOtherRecords) { var addressLogs = AddressLogRecord.GetLogs(session, payer.Addresses); var auditLogs = PayerAuditRecord.Find(payer); var logs = addressLogs.Select(log => GetLogRecord(log)); logs = logs.Concat(auditLogs.Select(r => r.ToAuditRecord())); if (showOtherRecords) { logs = logs.Concat(payer.GetAuditLogs()); } logs = logs.OrderByDescending(r => r.LogTime).ToList(); var operators = logs.Select(l => l.OperatorName).Distinct().ToList(); var admins = ActiveRecordLinqBase <Administrator> .Queryable .Where(a => operators.Contains(a.UserName)) .ToList() .GroupBy(a => a.UserName.ToLowerInvariant()) .Select(g => g.First()) .ToDictionary(a => a.UserName.ToLowerInvariant()); foreach (var log in logs) { var key = log.OperatorName.ToLowerInvariant(); if (admins.ContainsKey(key)) { var administrator = admins[key]; log.OperatorName = administrator.ManagerName; } } return(logs.ToList()); }
private static AuditLogRecord GetLogRecord(AddressLogRecord addressLogRecord) { var log = new AuditLogRecord { ObjectId = addressLogRecord.Address.Id, LogTime = addressLogRecord.LogTime, LogType = LogObjectType.Address, OperatorName = addressLogRecord.OperatorName, Message = ViewHelper.HumanReadableStatus(addressLogRecord.Enabled), Name = addressLogRecord.Address.Value, Comment = addressLogRecord.Comment }; return(log); }
public MonorailMailer EnableChanged(IEnablable item, string comment = null) { Template = "EnableChanged"; To = Config != null ? Config.RegisterListEmail : "*****@*****.**"; From = "*****@*****.**"; var lastDisable = "неизвестно"; var reasonDisable = "неизвестно"; var type = ""; var clazz = NHibernateUtil.GetClass(item); if (clazz == typeof(User)) { type = "пользователя"; var user = (User)item; PropertyBag["service"] = user.RootService; var disable = UserLogRecord.LastOff(user.Id); if (disable != null) { lastDisable = String.Format("{0} пользователем {1}", disable.LogTime, disable.OperatorName); if (!item.Enabled) { disable.Comment = comment; disable.Save(); } reasonDisable = disable.Comment; } } if (clazz == typeof(Address)) { type = "адреса"; var address = (Address)item; PropertyBag["service"] = address.Client; var disable = ArHelper.WithSession(session => AddressLogRecord.LastOff(session, address.Id)); if (disable != null) { lastDisable = String.Format("{0} пользователем {1}", disable.LogTime, disable.OperatorName); if (!item.Enabled) { disable.Comment = comment; ActiveRecordMediator.Save(disable); } reasonDisable = disable.Comment; } } if (clazz == typeof(Client)) { type = "клиента"; var client = ActiveRecordMediator <Client> .FindByPrimaryKey(((Service)item).Id); PropertyBag["service"] = client; var disable = ClientLogRecord.LastOff(client); if (disable != null) { lastDisable = String.Format("{0} пользователем {1}", disable.LogTime, disable.OperatorName); if (!item.Enabled) { disable.Comment = comment; disable.Save(); } reasonDisable = disable.Comment; } } if (clazz == typeof(Supplier)) { type = "поставщика"; PropertyBag["service"] = item; var disable = DbSession.Query <SupplierLog>().Where(s => s.Supplier == (Supplier)item && s.Disabled != null && s.Disabled == true).OrderByDescending(s => s.LogTime).FirstOrDefault(); if (disable != null) { lastDisable = String.Format("{0} пользователем {1}", disable.LogTime, disable.OperatorName); if (!item.Enabled) { disable.Comment = comment; DbSession.Save(disable); } reasonDisable = disable.Comment; } } if (item.Enabled) { Subject = String.Format("Возобновлена работа {0}", type); } else { Subject = String.Format("Приостановлена работа {0}", type); } if (!string.IsNullOrEmpty(lastDisable)) { PropertyBag["lastDisable"] = lastDisable; } PropertyBag["item"] = item; PropertyBag["admin"] = SecurityContext.Administrator; if (!string.IsNullOrEmpty(reasonDisable)) { PropertyBag["reasonDisable"] = reasonDisable; } return(this); }