public static List <PriceModel> GetGia_Api(PriceParamModel productmodel) { try { var client = new RestClient(Globals.VTAWebAPIUrl); var req = new RestRequest("vnpost-api/price/ListPriceByBranch", Method.POST) { RequestFormat = DataFormat.Json }; req.AddBody(productmodel); var rs = client.Execute <HttpContentResult <List <PriceModel> > >(req).Data; if (rs.Data == null && rs.StatusCode != "200") { return(null); } return(rs.Data); } catch (Exception ex) { var param = productmodel.ProductCodes.Aggregate(string.Empty, (current, item) => current + item + ","); param = param + " | " + productmodel.StoreCode; NLog.LogManager.GetCurrentClassLogger().Debug(" vnpost-api/price/ListPriceByBranch - Ex: - ({0}) - Param: {1}", ex.ToString(), param); return(null); } }
public IEnumerable <ProductHomeModel> GetListProduct(List <ProdectCode> ListProducts) { var pr = new PriceParamModel() { ProductCodes = ListProducts.Select(c => c.ProductCode).ToList(), StoreCode = Globals.StoreCodeConfig.Vnpost }; var listGia = PriceService.GetGia_Api(pr); var rs = new List <ProductHomeModel>(); foreach (var item in ListProducts) { var itemGia = listGia.FirstOrDefault(c => c.Productcode == item.ProductCode); rs.Add(new ProductHomeModel() { ProductId = Convert.ToInt32(item.ProductId), CategoryId = Convert.ToInt32(item.CategoryId), RootCategoryId = Convert.ToInt32(item.ParentId), ProductCode = item.ProductCode, ProductName = item.ProductName, ImageDetail = item.ImageDetail, PriceExpected = Convert.ToDecimal(item.PriceExpected), StatusExist = item.StatusExist, PriceOnline = itemGia == null ? -1 : itemGia.GiaChiNhanh, PriceUnderOnline = itemGia == null ? -1 : itemGia.GiaNiemYet, PriceHeadOffice = itemGia == null ? -1 : itemGia.GiaHeadOffice, PriceUnderHeadOffice = itemGia == null ? -1 : itemGia.GiaNiemYetHeadOffice, PromotionProduct = "", ProductFeatures = item.ProductFeatures, ProductShortDesc = item.ProductShortDesc, ProductDesc = item.ProductDesc, ProductStandardDesc = item.ProductStandardDesc, SeoKeyword = item.SeoKeyword, SeoDescription = item.SeoDescription, SeoTitle = item.SeoTitle, Slug = item.Slug, ProductStandardImage = item.ProductStandardImage }); } return(GetPromotionProdut(rs)); }
public HappyCareModel GetProductHappyCareModel(int productId, decimal price, string storeCode) { HappyCareDetailModel modelGhbh = new HappyCareDetailModel(); HappyCareDetailModel modelBvtd = new HappyCareDetailModel(); var tblCategory = _unitOfWork.Repository <P_Category>().Queryable(); var tblHappyCare = _unitOfWork.Repository <P_Happycare>().Queryable(); var tblProduct = _unitOfWork.Repository <P_Product>().Queryable(); var firstOrDefault = (from p in tblProduct join c in tblCategory on p.CategoryId equals c.CategoryId where p.ProductId == productId select new { idPath = c.IdPath }).FirstOrDefault(); if (firstOrDefault != null) { var idPath = firstOrDefault.idPath; var rsCategory = 0; //Nếu là Iphone rsCategory = idPath.Contains("152708") ? 152708 : Convert.ToInt32(idPath.Split('/').Any() ? idPath.Split('/')[0] : idPath); var happycare = tblHappyCare.FirstOrDefault( c => c.MinPrice <= price && c.MaxPrice >= price && c.CategoryId == rsCategory); if (happycare != null) { var lstHappyCare = new List <string>() { happycare.GHBHCode, happycare.BVTDCode }; var reqPriceModel = new PriceParamModel { ProductCodes = lstHappyCare, StoreCode = storeCode }; var qr = tblProduct.Where(c => lstHappyCare.Contains(c.ProductCode)).ToList(); //Lay Gia var rsApi = PriceService.GetGia_Api(reqPriceModel); var checkPriceByListCodeInfoBv = rsApi.FirstOrDefault(c => c.Productcode == happycare.BVTDCode); if (checkPriceByListCodeInfoBv != null) { var pProduct = qr.FirstOrDefault(c => c.ProductCode == happycare.BVTDCode); if (pProduct != null) { modelBvtd = new HappyCareDetailModel { price = Convert.ToInt32(checkPriceByListCodeInfoBv.GiaChiNhanh), product_id = pProduct.ProductId.ToString(), HappyCareName = "Bảo vệ toàn diện", ParentId = productId, ProductColorCode = pProduct.ProductCode } } ; } var checkPriceByListCodeInfoGh = rsApi.FirstOrDefault(c => c.Productcode == happycare.GHBHCode); if (checkPriceByListCodeInfoGh != null) { var pProduct = qr.FirstOrDefault(c => c.ProductCode == happycare.GHBHCode); if (pProduct != null) { modelGhbh = new HappyCareDetailModel { price = Convert.ToInt32(checkPriceByListCodeInfoGh.GiaChiNhanh), product_id = pProduct.ProductId.ToString(), HappyCareName = "Gia hạn bảo hành", ParentId = productId, ProductColorCode = pProduct.ProductCode } } ; } } } return(new HappyCareModel(modelGhbh, modelBvtd)); }
public List <ProductHomeModel> ListAllProduct() { var pProduct = _unitOfWork.Repository <P_Product>().Queryable().Where(c => c.Status == "A"); var pCategory = _unitOfWork.Repository <P_Category>().Queryable().Where(c => c.Status == "A"); var BusinessId = _unitOfWork.Repository <A_Business_products>().Queryable().Where(c => c.Status == "A" && c.Business_campaign_id == Globals.BusinessConfig.Vnpost).Select(s => s.Product_code).Distinct(); var query = (from p in pProduct join c in pCategory on p.CategoryId equals c.CategoryId where BusinessId.Contains(p.ProductCode) select new { p.ProductId, p.CategoryId, c.ParentId, p.ProductCode, p.ProductName, p.ProductImage, p.PriceExpected, p.StatusExsit, p.ProductFeatures, p.ProductShortDesc, p.ProductDesc, p.ProductStandardDesc, p.ProductStandardImage, p.SeoKeyword, p.SeoTitle, p.SeoDescription, p.Slug }).OrderBy(c => c.ProductId).ToList(); var pr = new PriceParamModel() { ProductCodes = query.Select(c => c.ProductCode).ToList(), StoreCode = Globals.StoreCodeConfig.Vnpost }; var listGia = PriceService.GetGia_Api(pr); var rs = new List <ProductHomeModel>(); foreach (var item in ListProducts) { var itemGia = listGia.FirstOrDefault(c => c.Productcode == item.ProductCode); rs.Add(new ProductHomeModel() { ProductId = Convert.ToInt32(item.ProductId), CategoryId = Convert.ToInt32(item.CategoryId), RootCategoryId = Convert.ToInt32(item.RootCategoryId), ProductCode = item.ProductCode, ProductName = item.ProductName, ImageDetail = item.ImageDetail, PriceExpected = Convert.ToDecimal(item.PriceExpected), StatusExist = item.StatusExist, PriceOnline = itemGia == null ? -1 : itemGia.GiaChiNhanh, PriceUnderOnline = itemGia == null ? -1 : itemGia.GiaNiemYet, PriceHeadOffice = itemGia == null ? -1 : itemGia.GiaHeadOffice, PriceUnderHeadOffice = itemGia == null ? -1 : itemGia.GiaNiemYetHeadOffice, PromotionProduct = "", ProductFeatures = item.ProductFeatures, ProductShortDesc = item.ProductShortDesc, ProductDesc = item.ProductDesc, ProductStandardDesc = item.ProductStandardDesc, SeoKeyword = item.SeoKeyword, SeoDescription = item.SeoDescription, SeoTitle = item.SeoTitle, Slug = item.Slug, ProductStandardImage = item.ProductStandardImage }); } return(rs); //return query.Select(item => new ProdectCode() //{ // ProductId = Convert.ToInt32(item.ProductId), // CategoryId = Convert.ToInt32(item.CategoryId), // ParentId = Convert.ToInt32(item.ParentId), // ProductCode = item.ProductCode, // ProductName = item.ProductName, // ImageDetail = item.ProductImage, // PriceExpected = Convert.ToDecimal(item.PriceExpected), // StatusExist = item.StatusExsit, // ProductFeatures = item.ProductFeatures, // ProductShortDesc = item.ProductShortDesc, // ProductDesc = item.ProductDesc, // ProductStandardDesc = item.ProductStandardDesc, // SeoKeyword = item.SeoKeyword, // SeoTitle = item.SeoTitle, // SeoDescription = item.SeoDescription, // Slug = item.Slug, // ProductStandardImage = item.ProductStandardImage //}).ToList(); }