public ActionResult AddProduct(ProductDto product)
 {
     using (var proxy = new ProductServiceClient())
     {
         if (string.IsNullOrEmpty(product.ImageUrl))
         {
             var fileName = Guid.NewGuid() + ".png";
             System.IO.File.Copy(Server.MapPath("~/Images/Products/ProductImage.png"), Server.MapPath(string.Format("~/Images/Products/{0}", fileName)));
             product.ImageUrl = fileName;
         }
         var addedProducts = proxy.CreateProducts(new List <ProductDto> {
             product
         }.ToArray());
         if (product.Category != null &&
             product.Category.Id != Guid.Empty.ToString())
         {
             proxy.CategorizeProduct(new Guid(addedProducts[0].Id), new Guid(product.Category.Id));
         }
         return(RedirectToSuccess("添加商品信息成功!", "Products", "Admin"));
     }
 }
示例#2
0
 public ActionResult AddProduct(ProductDto product)
 {
     using (var proxy = new ProductServiceClient())
     {
         if (string.IsNullOrEmpty(product.ImageUrl))
         {
             var fileName = Guid.NewGuid() + ".png";
             System.IO.File.Copy(Server.MapPath("~/Images/Products/ProductImage.png"), Server.MapPath(string.Format("~/Images/Products/{0}", fileName)));
             product.ImageUrl = fileName;
         }
         var addedProducts = proxy.CreateProducts(new List<ProductDto> { product }.ToArray());
         if (product.Category != null &&
             product.Category.Id != Guid.Empty.ToString())
             proxy.CategorizeProduct(new Guid(addedProducts[0].Id), new Guid(product.Category.Id));
         return RedirectToSuccess("添加商品信息成功!", "Products", "Admin");
     }
 }
示例#3
0
 public ActionResult EditProduct(ProductDto product)
 {
     using (var proxy = new ProductServiceClient())
     {
         proxy.UpdateProducts(new List<ProductDto> { product }.ToArray());
         if (product.Category.Id != Guid.Empty.ToString())
             proxy.CategorizeProduct(new Guid(product.Id), new Guid(product.Category.Id));
         else
             proxy.UncategorizeProduct(new Guid(product.Id));
         return RedirectToSuccess("更新商品信息成功!", "Products", "Admin");
     }
 }