public static Category ToViewModel(this DataContracts.Category category) { var categoryViewModel = new Category(); categoryViewModel.Code = category.Code; categoryViewModel.Id = category.Id; if (category.Image != null) { categoryViewModel.Image = category.Image.ToViewModel(); } if (category.Seo != null) { var seo = category.Seo.FirstOrDefault(s => !string.IsNullOrEmpty(s.Keyword)); if (seo != null) { categoryViewModel.Slug = seo.Keyword; } } if (category.Parents != null) { foreach (var parentCategory in category.Parents) { categoryViewModel.ParentCategories.Add(parentCategory.ToViewModel()); } } categoryViewModel.Title = category.Name; return(categoryViewModel); }
public static Category ToViewModel(this DataContracts.Category category) { var categoryModel = new Category(); categoryModel.Id = category.Id; categoryModel.Name = category.Name; categoryModel.Slug = category.Code; if (category.Seo != null) { var seo = category.Seo.FirstOrDefault(s => !string.IsNullOrEmpty(s.Keyword)); if (seo != null) { categoryModel.Slug = seo.Keyword; } } return(categoryModel); }
public static Collection AsWebModel(this Data.Category category) { var collection = new Collection(); var urlTemplate = VirtualPathUtility.ToAbsolute("~/collections/{0}"); collection.AllTypes = null; // TODO collection.AllVendors = null; // TODO collection.CurrentType = null; // TODO collection.CurrentVendor = null; // TODO collection.DefaultSortBy = "manual"; collection.Description = null; // TODO collection.Handle = category.Code; collection.Id = category.Id; if (category.Image != null) { collection.Image = category.Image.AsWebModel(category.Image.Name, category.Id); } collection.Keywords = category.Seo != null?category.Seo.Select(k => k.AsWebModel()) : null; collection.NextProduct = null; // TODO collection.Parents = category.Parents != null?category.Parents.Select(p => p.AsWebModel()) : null; collection.PreviousProduct = null; // TODO collection.TemplateSuffix = null; // TODO collection.Title = category.Name; collection.Url = string.Format(urlTemplate, category.Code); // specify SEO based url var outline = collection.BuildOutline(Thread.CurrentThread.CurrentUICulture.Name).Select(x => x.Value); if (outline.Any()) { var urlHelper = GetUrlHelper(); collection.Outline = string.Join("/", outline); collection.Url = urlHelper.CategoryUrl(collection.Outline); } return(collection); }
private string GetOutline(Category category) { var ids = category.Parents != null ? category.Parents.Select(x => x.Id).ToList() : new List<string>(); ids.Add(category.Id); return string.Join("/", ids); }