Esempio n. 1
0
        public bool SaveEntity(string[] productImages, int productId)
        {
            try
            {
                if (productId > 0)
                {
                    var oldProductImages = _productImagesRepository.FindAll().Where(q => q.ProductId == productId).ToList();
                    if (oldProductImages != null && oldProductImages.Count > 0)
                    {
                        _productImagesRepository.RemoveMultiple(oldProductImages);
                    }
                    foreach (var item in productImages)
                    {
                        var objImg = new ProductImagesModel();
                        objImg.ProductId = productId;
                        objImg.Url       = item;
                        _productImagesRepository.Add(objImg.ToProductImages());
                    }
                    Save();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                return(false);

                throw;
            }
            return(false);
        }
 /// <summary>
 /// 商品详情页产品信息
 /// </summary>
 /// <param name="productid"></param>
 /// <returns></returns>
 public ProductDetailsPageModel GetSingleProductDetails(int productid)
 {
     ProductDetailsPageModel productmodel = new ProductDetailsPageModel();
     productmodel.product = dal.GetSingleProductInfo(productid);//获取商品信息
     DataTable imgdt = dal.GetProductMainimageByPid(productid);//获取主图
     List<ProductImagesModel> proimglist = new List<ProductImagesModel>();
     foreach (DataRow item in imgdt.Rows)
     {
         ProductImagesModel model = new ProductImagesModel();
         model.showimg = item["showimg"].ToString();
         model.pimgid = int.Parse(item["pimgid"].ToString());
         proimglist.Add(model);
     }
     productmodel.MainImages = proimglist;
     DataTable catedt = catedal.GetRelevantCategoryByProductid(productid);//得到相关分类
     List<CategoriesModel> categorylist = new List<CategoriesModel>();
     foreach (DataRow item in catedt.Rows)
     {
         CategoriesModel model = new CategoriesModel();
         model.cateid=int.Parse(item["cateid"].ToString());
         model.name = item["name"].ToString();
         categorylist.Add(model);
     }
     productmodel.category = categorylist;
     DataTable brandt = catedal.GetRelevantBrandsByProductid(productid);//得到相关品牌
     List<BrandsModel> brandslist = new List<BrandsModel>();
     foreach (DataRow item in brandt.Rows)
     {
         BrandsModel model = new BrandsModel();
         model.brandid = int.Parse(item["brandid"].ToString());
         model.name = item["name"].ToString();
         brandslist.Add(model);
     }
     productmodel.brands = brandslist;
     DataTable prodt = dal.GetRelevantHotMaleProduct(productid);//得到热卖产品列表
     List<ProductsModel> productlist = new List<ProductsModel>();
     foreach (DataRow item in prodt.Rows)
     {
         ProductsModel model = new ProductsModel();
         model.ShowimgPath = item["ShowimgPath"].ToString();
         model.pid = int.Parse(item["pid"].ToString());
         model.ProductName = item["ProductName"].ToString();
         model.Shopprice = decimal.Parse(item["Shopprice"].ToString());
         productlist.Add(model);
     }
     productmodel.BestProducts = productlist;
     return productmodel;
 }
Esempio n. 3
0
 public static ProductImages ToProductImages(this ProductImagesModel entity)
 {
     return(entity.MapTo <ProductImagesModel, ProductImages>());
 }