public static T ToABPageTestResultEntity <T>(this ABPageTestResult model, T entity) where T : IABPageTestResultEntity { entity.UUID = model.UUID; if (null != model.Site) { entity.SiteName = model.Site.FullName; } entity.ObjectXml = DataContractSerializationHelper.SerializeAsXml(model, KnownTypes); return(entity); }
private void UpdateOrAdd(ABPageTestResult item, ABPageTestResult oldItem) { ((IPersistable)item).OnSaving(); var dummy = _dbContext.ABPageTestResults.FirstOrDefault(it => it.UUID.Equals(oldItem.UUID, StringComparison.OrdinalIgnoreCase) && it.SiteName.Equals(oldItem.Site.FullName, StringComparison.OrdinalIgnoreCase)); if (null != dummy) { item.ToABPageTestResultEntity <ABPageTestResultEntity>(dummy); } else { dummy = item.ToABPageTestResultEntity <ABPageTestResultEntity>(); _dbContext.ABPageTestResults.Add(dummy); } _dbContext.SaveChanges(); ((IPersistable)item).OnSaved(); }
public static ABPageTestResult ToABPageTestResult(this IABPageTestResultEntity entity) { if (entity == null) { return(null); } var dummy = new ABPageTestResult(); dummy.UUID = entity.UUID; dummy.Site = new Site(entity.SiteName); var result = DataContractSerializationHelper.DeserializeFromXml <ABPageTestResult>(entity.ObjectXml, KnownTypes); ((IPersistable)result).Init(dummy); return(result); }
public static T ToABPageTestResultEntity <T>(this ABPageTestResult model) where T : IABPageTestResultEntity, new() { return(ToABPageTestResultEntity(model, new T())); }