public static LastChangeModel GetLastChangeModel(PersonLog log) { return(log != null ? new LastChangeModel { Date = log.Date.ToString("G") + " +0000", UserName = $"{log.User.Name} {log.User.LastName}" } : null); }
private void SaveLog <T>(T from, T to, int personId, int userId, LogType type) where T : BaseEntity { var log = new PersonLog { Date = DateTime.UtcNow, UserId = userId, IdPerson = personId, IdProperty = to.Id, Type = type, ChengeFrom = JsonConvert.SerializeObject(from), ChangeTo = JsonConvert.SerializeObject(to) }; db.Entry(log).State = System.Data.Entity.EntityState.Added; //db.PersonLogs.Add(log); //db.SaveChanges(); }
public static async Task Run([EventHubTrigger("person.personlog", Connection = "evh-bl-tutorial")] EventData[] events, [CosmosDB(ConnectionStringSetting = "cosmos-bl-tutorial-serverless")] DocumentClient documentClient, ILogger log) { var exceptions = new List<Exception>(); var eventList = events.GetData<EventGridEvent>(); foreach (var eventData in eventList) { try { var person = JsonConvert.DeserializeObject<Person>(eventData.Data.ToString()); var personLog = new PersonLog() { Name = person.FirstName + " " + person.LastName, City = person.City, Data = eventData.Data.ToString() }; var repsPersonLog = new PersonLogRepository(documentClient); await repsPersonLog.CreateAsync(personLog); } catch (Exception e) { // We need to keep processing the rest of the batch - capture this exception and continue. // Also, consider capturing details of the message that failed processing so it can be processed again later. exceptions.Add(e); } } // Once processing of the batch is complete, if any messages in the batch failed processing throw an exception so that there is a record of the failure. if (exceptions.Count > 1) throw new AggregateException(exceptions); if (exceptions.Count == 1) throw exceptions.Single(); }