public static void AddImportLogClientCreate(IEnumerable<Client> clients) { var importLogId = _unitOfWork.ImportLogRepository.GetAll().OrderByDescending(x => x.ImportDate).First().Id; foreach (var client in clients) { var newComment = ""; foreach (PropertyInfo propertyInfo in client.GetType().GetProperties()) { if (!propertyInfo.PropertyType.IsGenericType) { newComment += propertyInfo.Name + " : " + propertyInfo.GetValue(client, null) + ", ";//??SentSMS,ClientComment } } var importLogClient = new ImportLogClient { Id = Guid.NewGuid(), ClientId = client.Id, ImportLogId = importLogId, Action = ActiontImportLogType.NewClient, Comments = newComment }; _unitOfWork.ImportLogClientRepository.Add(importLogClient); } _unitOfWork.ImportLogClientRepository.Save(); }
public static void AddImportLogClientUpdate(IEnumerable<Client> clients) { var importLogId = _unitOfWork.ImportLogRepository.GetAll().OrderByDescending(x => x.ImportDate).First().Id; using (var context = new BaseDbContext()) { foreach (var client in clients) { var originalClient = context.Clients.SingleOrDefault(cl => cl.Id == client.Id); var parentEntry = context.Entry(originalClient); parentEntry.CurrentValues.SetValues(client); var nameProperties = parentEntry.CurrentValues.PropertyNames.Where(propertyName => parentEntry.Property(propertyName).IsModified).ToList(); var newComment = ""; foreach (var nameProperty in nameProperties) { var property = parentEntry.Property(nameProperty); if (property.IsModified == true) { newComment += property.Name + " : " + property.OriginalValue + " -> " + property.CurrentValue + ", "; } } var importLogClient = new ImportLogClient { Id = Guid.NewGuid(), ClientId = parentEntry.Entity.Id, ImportLogId = importLogId, Action = ActiontImportLogType.EditedClient, Comments = newComment }; _unitOfWork.ImportLogClientRepository.Add(importLogClient); } } _unitOfWork.ImportLogClientRepository.Save(); _unitOfWork.ClientRepository.Save(); }