Ejemplo n.º 1
0
 public bool Delete(ProductEntity entity)
 {
     try
     {
         _productRepository.Delete(entity);
         return true;
     }
     catch (Exception e)
     {
         _log.Error(e, "数据库操作出错");
         return false;
     }
 }
Ejemplo n.º 2
0
 public ProductEntity Update(ProductEntity entity)
 {
     try
     {
         _productRepository.Update(entity);
         return entity;
     }
     catch (Exception e)
     {
         _log.Error(e, "数据库操作出错");
         return null;
     }
 }
        /// <summary>
        /// 添加商品
        /// </summary>
        /// <param name="model">商品model</param>
        /// <returns>提示信息</returns>
		public HttpResponseMessage Post(ProductModel model)
		{
		    var category = _categoryService.GetCategoryById(model.CategoryId);
			var entity = new ProductEntity
			{
                Category = category,
				BussnessId = model.BussnessId,
				BussnessName =model.BussnessName,
				Price = model.Price,
				Name = model.Name,
				Status = model.Status,
				MainImg = model.MainImg,
				IsRecommend =model.IsRecommend,
				Sort = model.Sort,
				Stock = model.Stock,
				AddUser = _workContext.CurrentUser.Id,
				AddTime =DateTime.Now,
				UpdUser =_workContext.CurrentUser.Id,
				UpdTime = DateTime.Now,
				Subtitte = model.Subtitte,
				Contactphone = model.Contactphone,
				Type =model.Type,
                OldPrice =model.OldPrice,
                Owner = model.Owner
			   // Detail = model.Detail,
				//Comments = model.Comments,
//				Parameters = model.Parameters,
			};
		    int id = _productService.Create(entity).Id; 
			if(id> 0)
			{               
				var productDetail = new ProductDetailEntity
               {
                    Id = id,
                    Name = model.Name,
                    Detail = model.Detail,
                    Img = model.Img,
                    Img1 = model.Img1,
                    Img2 = model.Img2,
                    Img3 = model.Img3,
                    Img4 = model.Img4,
                    SericeInstruction = model.SericeInstruction,
                    AddUser = _workContext.CurrentUser.Id,
                    AddTime = DateTime.Now,
                    UpdUser = _workContext.CurrentUser.Id,
                    UpdTime = DateTime.Now,
                    Ad1 = model.Ad1,
                    Ad2 = model.Ad2,
                    Ad3 = model.Ad3,
                };              
                if (_productDetailService.Create(productDetail).Id>0)
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(true,"数据添加成功"));
                }
			    return PageHelper.toJson(PageHelper.ReturnValue(false,"商品详细添加失败"));
			}            
			return PageHelper.toJson(PageHelper.ReturnValue(false,"数据添加失败"));
		}