public void Update(NotificationTemplate[] notificationTemplates) { using (var repository = _repositoryFactory()) using (var changeTracker = base.GetChangeTracker(repository)) { foreach (var notificationTemplate in notificationTemplates) { var sourceEntity = notificationTemplate.ToDataModel(); NotificationTemplateEntity targetEntity = null; if (!sourceEntity.IsTransient()) { targetEntity = repository.NotificationTemplates.FirstOrDefault(x => x.Id == sourceEntity.Id); } else { targetEntity = repository.GetNotificationTemplateByNotification(notificationTemplate.NotificationTypeId, notificationTemplate.ObjectId, notificationTemplate.ObjectTypeId, notificationTemplate.Language); } if (targetEntity == null) { repository.Add(sourceEntity); } else { changeTracker.Attach(targetEntity); sourceEntity.Patch(targetEntity); } } CommitChanges(repository); } }
public static Core.Notification.NotificationTemplate ToCoreModel(this NotificationTemplateEntity notificationTemplate) { Core.Notification.NotificationTemplate retVal = new Core.Notification.NotificationTemplate(); retVal.InjectFrom(notificationTemplate); return(retVal); }
public static NotificationTemplateEntity ToDataModel(this Core.Notification.NotificationTemplate notificationTemplate) { NotificationTemplateEntity retVal = new NotificationTemplateEntity(); retVal.InjectFrom(notificationTemplate); return(retVal); }
public static void Patch(this NotificationTemplateEntity source, NotificationTemplateEntity target) { if (target == null) { throw new ArgumentNullException("target"); } var patchInjection = new PatchInjection <NotificationTemplateEntity>(x => x.Subject, x => x.Body, x => x.IsDefault); target.InjectFrom(patchInjection, source); }