Exemplo n.º 1
0
 /// <summary>
 /// 获取商品详情
 /// </summary>
 /// <param name="id">商品Id</param>
 /// <returns>商品实体</returns>
 public HttpResponseMessage Get(int id)
 {
     var entity = _productService.GetProductById(id);
     var comment = entity.Comments;
     List<ProductCommentModel> commentList;
     if (comment == null)
     {
         commentList = new List<ProductCommentModel>();
     }
     else
     {
         commentList = (from c in comment
                 select new ProductCommentModel
                 {
                     Id = c.Id,
                     Content = c.Content,
                     AddTime = c.AddTime,
                    // AddUser = c.AddUser
                 }).ToList();
     }
     var model = new ProductModel
     {               
         BussnessId = entity.BussnessId,
         BussnessName = entity.BussnessName,
         Price = entity.Price,
         Name = entity.Name,
         Status = entity.Status,
         MainImg = entity.MainImg,
         IsRecommend = entity.IsRecommend,
         Sort = entity.Sort,
         Stock = entity.Stock,
         Subtitte = entity.Subtitte,
         Contactphone = entity.Contactphone,
         SericeInstruction = entity.Detail.SericeInstruction,
         Type = entity.Type               
     };
     var product = new ProductComment
     {
         ProductModel = model,
         Comments = commentList
     };
     return PageHelper.toJson(product);
 }
        /// <summary>
        /// 获取商品详情
        /// </summary>
        /// <param name="id">商品Id</param>
        /// <returns>商品实体</returns>
        public HttpResponseMessage Get(int id)
		{
			var entity =_productService.GetProductById(id);
            if (entity == null)
            {
                return PageHelper.toJson(PageHelper.ReturnValue(false, "数据不存在"));
            }
            var comment = entity.Comments;           
            List<ProductCommentModel> commentList;
            if (comment == null)
            {
                commentList = new List<ProductCommentModel>();
            }
            else
            {
                commentList = (from c in comment
                        select new ProductCommentModel
                        {
                            Id = c.Id,
                            Content = c.Content,
                            AddTime = c.AddTime,
                            //AddUser = c.AddUser
                        }).ToList();
            }
			var model = new ProductModel
			{
				Id = entity.Id,	
                CategoryId = entity.Category.Id,	
                BussnessId= entity.BussnessId,	
                BussnessName = entity.BussnessName,	
                Price = entity.Price,		
                Name = entity.Name,			
                Status = entity.Status,		
                MainImg = entity.MainImg,
		        Img = entity.Detail.Img,
                Img1 = entity.Detail.Img1,
                Img2 = entity.Detail.Img2,
                Img3 = entity.Detail.Img3,
                Img4 = entity.Detail.Img4,
                IsRecommend = entity.IsRecommend,
                Sort = entity.Sort,				
                Stock = entity.Stock,		            	
                Subtitte = entity.Subtitte,				
                Contactphone = entity.Contactphone,
                SericeInstruction = entity.Detail.SericeInstruction,
                Type = entity.Type,
			    OldPrice = entity.OldPrice,
                Owner = entity.Owner,
                Detail = entity.Detail.Detail,
		        Ad1 = entity.Detail.Ad1,
                Ad2 = entity.Detail.Ad2,
                Ad3 = entity.Detail.Ad3,
                //Comments = entity.Comments,		
                //ParameterValue =entity.Parameters.Select(c => new ProductParameterValueModel
                //{
                //    ParameterId = c.Parameter.Id,
                //    ParameterString = c.Parameter.Name,
                //    ValueId = c.ParameterValue.Id,
                //    Value = c.ParameterValue.Value
                //}).ToList()
            };
            var product=new ProductComment
            {
                ProductModel = model,
                Comments = commentList
            };
			return PageHelper.toJson(product);
		}