/// <summary> /// Converting to foundation type /// </summary> /// <param name="category">The category.</param> /// <returns></returns> public static dataModel.Category ToDataModel(this coreModel.Category category) { var retVal = new dataModel.Category(); var id = retVal.Id; retVal.InjectFrom(category); if(category.Id == null) { retVal.Id = id; } retVal.ParentCategoryId = category.ParentId; retVal.EndDate = DateTime.UtcNow.AddYears(100); retVal.StartDate = DateTime.UtcNow; retVal.IsActive = category.IsActive ?? true; if (category.PropertyValues != null) { retVal.CategoryPropertyValues = new ObservableCollection<dataModel.CategoryPropertyValue>(); retVal.CategoryPropertyValues.AddRange(category.PropertyValues.Select(x => x.ToDataModel<dataModel.CategoryPropertyValue>()).OfType<dataModel.CategoryPropertyValue>()); } if (category.Links != null) { retVal.OutgoingLinks = new ObservableCollection<dataModel.CategoryRelation>(); retVal.OutgoingLinks.AddRange(category.Links.Select(x => x.ToDataModel(category))); } #region Images if (category.Images != null) { retVal.Images = new ObservableCollection<dataModel.Image>(category.Images.Select(x=>x.ToDataModel())); } #endregion return retVal; }
/// <summary> /// Converting to foundation type /// </summary> /// <param name="category">The category.</param> /// <returns></returns> public static dataModel.Category ToDataModel(this coreModel.Category category, PrimaryKeyResolvingMap pkMap) { var retVal = new dataModel.Category(); pkMap.AddPair(category, retVal); retVal.InjectFrom(category); retVal.ParentCategoryId = category.ParentId; retVal.EndDate = DateTime.UtcNow.AddYears(100); retVal.StartDate = DateTime.UtcNow; retVal.IsActive = category.IsActive ?? true; if (category.PropertyValues != null) { retVal.CategoryPropertyValues = new ObservableCollection<dataModel.PropertyValue>(); retVal.CategoryPropertyValues.AddRange(category.PropertyValues.Select(x => x.ToDataModel(pkMap))); } if (category.Links != null) { retVal.OutgoingLinks = new ObservableCollection<dataModel.CategoryRelation>(); retVal.OutgoingLinks.AddRange(category.Links.Select(x => x.ToDataModel(category))); } #region Images if (category.Images != null) { retVal.Images = new ObservableCollection<dataModel.Image>(category.Images.Select(x=>x.ToDataModel(pkMap))); } #endregion return retVal; }
private static Category CloneCategory(Category category) { return new Category { Id = category.Id, ParentCategoryId = category.ParentCategoryId, CatalogId = category.CatalogId, Catalog = _catalogs.FirstOrDefault(c => c.Id == category.CatalogId), }; }