public static ProductModel ToModel(this Product entity) { var model = new ProductModel(); Mapper.CreateMap<Product, ProductModel>() .ForMember(m => m.CategoryAlias, conf => conf.MapFrom(m => m.Category.Alias)); Mapper.Map(entity, model); return model; //Mapper.CreateMap<Product, ProductModel>(); // Mapper.Map<Product, ProductModel>(entity); }
public ActionResult ProductDetail(string productAlias) { if (!string.IsNullOrEmpty(productAlias)) { var productKey = string.Format(PRODUCT_BY_ALIAS_KEY, productAlias); var model = new ProductModel(); model = HgtCache.Get<ProductModel>(productKey); if (model == null) { var product = _productService.GetProductByAlias(productAlias); if (product != null) { model = product.ToModel(); // get category model.Category = _categoryService.GetCategoryById(model.CategoryId); // get gallery images var galleryImageKey = string.Format(PRODUCT_GALLERY_PRODUCTID_BY_TYPE_KEY, model.Id, (int)GalleryType.ImageAndVideo); var galleryImage = new List<GalleryDetail>(); galleryImage = HgtCache.Get<List<GalleryDetail>>(galleryImageKey); if (galleryImage == null) { galleryImage = _galleryService.GetListGalleryDetailByObjectId(model.Id, (int)GalleryCategory.Product, (int)GalleryType.ImageAndVideo); HgtCache.Insert(galleryImageKey, galleryImage); } model.Galleries = galleryImage; // get gallery print var galleryPrintKey = string.Format(PRODUCT_GALLERY_PRODUCTID_BY_TYPE_KEY, model.Id, (int)GalleryType.PrintCapbility); var galleryPrint = new List<GalleryDetail>(); galleryPrint = HgtCache.Get<List<GalleryDetail>>(galleryPrintKey); if (galleryPrint == null) { galleryPrint = _galleryService.GetListGalleryDetailByObjectId(model.Id, (int)GalleryCategory.Product, (int)GalleryType.PrintCapbility); HgtCache.Insert(galleryPrintKey, galleryPrint); } model.Prints = galleryPrint; // cache HgtCache.Insert(productKey, model); } } if (model != null) return View(model); } return HttpNotFound(); }