public static string GetUrl(this ProductHomepageViewModel product) { if (product == null) { return(string.Empty); } return(string.Format("/{0}-p{1}.html", product.Name?.Editor(), product.Id)); }
private ProductHomepageViewModel getView() { ProductHomepageViewModel viewReturn = new ProductHomepageViewModel(); viewReturn.categoryHeaders = categoryHeaderRepository.GetAll(); viewReturn.products = productRepository.GetAll(); viewReturn.hereAreYou = " Home"; viewReturn.header = "Hardware"; return(viewReturn); }
public ProductController(IProductRepository iprepo, CategoryHeaderRepository cHR) { categoryHeaderRepository = cHR; productRepository = iprepo; productHpVModel = new ProductHomepageViewModel(); }
public async Task <ProductHomepageViewModel> GetProductDetailOfHomepageAsync(int productId, string lang = "vi") { ProductHomepageViewModel result = null; string cmd = $@"SELECT p.*, pl.*, pp.*, cte.* FROM `product` p LEFT JOIN `language` l ON l.code = '{lang}' LEFT JOIN `product_language` pl ON p.id = pl.product_id AND pl.language_id = l.id LEFT JOIN `product_price` pp ON pp.product_id = p.id LEFT JOIN {categoryQuery} cte ON cte.id = p.category_id WHERE p.id = {productId} and p.is_deleted = 0 AND p.is_used = '1'"; if (DbConnection != null) { var rd = await DbConnection.QueryMultipleAsync(cmd, transaction : DbTransaction); rd.Read <Product, ProductLanguage, ProductPrice, Category, ProductHomepageViewModel>( (pRs, plRs, ppRs, cteRs) => { if (result == null) { result = CommonHelper.Mapper <Product, ProductHomepageViewModel>(pRs); } if (plRs != null) { result.Name = string.IsNullOrWhiteSpace(plRs.Name) ? result.DefaultName : plRs.Name; result.Decription = string.IsNullOrWhiteSpace(plRs.Description) ? result.DefaultDescription : plRs.Description; } else { result.Name = result.DefaultName; result.Decription = result.DefaultDescription; } if (ppRs != null) { result.CurrentUoM = ppRs.UoMId; result.SellingCurrentPrice = ppRs.SellingPrice; var price = result.Prices.FirstOrDefault(l => l.Id == ppRs.Id); if (price == null) { result.Prices.Add(ppRs); } } else { result.CurrentUoM = result.DefaultUoMId; result.SellingCurrentPrice = result.DefaultSellingPrice; } if (cteRs != null) { result.Category = cteRs; } return(result); } ); return(result); } else { using (var conn = DALHelper.GetConnection()) { var rd = await conn.QueryMultipleAsync(cmd); rd.Read <Product, ProductLanguage, ProductPrice, Category, ProductHomepageViewModel>( (pRs, plRs, ppRs, cteRs) => { if (result == null) { result = CommonHelper.Mapper <Product, ProductHomepageViewModel>(pRs); } if (plRs != null) { result.Name = string.IsNullOrWhiteSpace(plRs.Name) ? result.DefaultName : plRs.Name; result.Decription = string.IsNullOrWhiteSpace(plRs.Description) ? result.DefaultDescription : plRs.Description; } else { result.Name = result.DefaultName; result.Decription = result.DefaultDescription; } if (ppRs != null) { result.CurrentUoM = ppRs.UoMId; result.SellingCurrentPrice = ppRs.SellingPrice; var price = result.Prices.FirstOrDefault(l => l.Id == ppRs.Id); if (price == null) { result.Prices.Add(ppRs); } } else { result.CurrentUoM = result.DefaultUoMId; result.SellingCurrentPrice = result.DefaultSellingPrice; } if (cteRs != null) { result.Category = cteRs; } return(result); } ); return(result); } } }