Exemple #1
0
        public static List <RecommendProductModel> GetTireEnforceRecommendByPids(List <string> pids)
        {
            var returnResult = new List <RecommendProductModel>();

            if (pids == null || !pids.Any() || pids.Count == 0)
            {
                return(returnResult);
            }
            try
            {
                using (var client = new ProductConfigClient())
                {
                    var result = client.GetTireEnforceRecommendByPids(pids.Distinct().ToList());
                    result.ThrowIfException(true);
                    if (result.Success && result.Result != null && result.Result.Any() && result.Result.Count > 0)
                    {
                        var recommendPids = result.Result.Where(p => !string.IsNullOrWhiteSpace(p.RecommendPID))
                                            .Select(p => p.RecommendPID)
                                            .Distinct()
                                            .ToList();
                        var displayNames   = DALRecommendTire.GetDisplayName(recommendPids);
                        var displayNameDic = displayNames?.GroupBy(p => p.PID)?.ToDictionary(p => p.Key?.ToUpper(), p => p.FirstOrDefault()?.DisplayName ?? "");
                        result.Result.ForEach(item =>
                        {
                            var model = new RecommendProductModel
                            {
                                PID          = item.PId,
                                Image        = item.Image,
                                Postion      = item.Position,
                                Reason       = item.Reason,
                                RecommendPID = item.RecommendPID,
                            };
                            var ProductName = "";
                            if ((bool)displayNameDic?.ContainsKey(model.RecommendPID?.ToUpper()))
                            {
                                displayNameDic.TryGetValue(model.RecommendPID?.ToUpper(), out ProductName);
                            }
                            model.ProductName = ProductName;
                            returnResult.Add(model);
                        });
                    }
                }
                return(returnResult);
            }
            catch (Exception ex)
            {
                //TODO:log
                return(returnResult);
            }
        }
Exemple #2
0
        public static List <RecommendProductModel> GetTireEnforceRecommendByPids(List <string> pids)
        {
            var returnResult = new List <RecommendProductModel>();

            if (pids == null || !pids.Any() || pids.Count == 0)
            {
                return(returnResult);
            }
            try
            {
                using (var client = new ProductConfigClient())
                {
                    var result = client.GetTireEnforceRecommendByPids(pids.Distinct().ToList());
                    result.ThrowIfException(true);
                    if (result.Success && result.Result != null && result.Result.Any() && result.Result.Count > 0)
                    {
                        var recommendPids = result.Result.Where(p => !string.IsNullOrWhiteSpace(p.RecommendPID))
                                            .Select(p => p.RecommendPID)
                                            .Distinct()
                                            .ToList();
                        var displayNames = DALRecommendTire.GetDisplayName(recommendPids);
                        result.Result.ForEach(item => returnResult.Add(new RecommendProductModel
                        {
                            PID          = item.PId,
                            Image        = item.Image,
                            Postion      = item.Position,
                            Reason       = item.Reason,
                            RecommendPID = item.RecommendPID,
                            ProductName  = displayNames.Where(p => p.PID == item.RecommendPID).FirstOrDefault().DisplayName
                        }));
                    }
                }
                return(returnResult);
            }
            catch (Exception ex)
            {
                //TODO:log
                return(returnResult);
            }
        }