Exemplo n.º 1
0
        public JsonResult PicDelete(long productID, long picID)
        {
            JsonResult result = new JsonResult {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            if (picID == 0)
            {
                return(result);
            }
            else
            {
                ProductPicture _PicModel = svc.SelectOrEmpty(
                    new ProductPictureQuery()
                {
                    IDs = new long[] { picID }
                }).FirstOrDefault();
                if (_PicModel != null)
                {
                    _pictureService.Delete(_PicModel);
                    svc.Delete(_PicModel);
                    result.Data = new { Success = true };
                }
                else
                {
                    result.Data = new { Success = false };
                }
                return(result);
            }
        }
Exemplo n.º 2
0
 public ActionResult Add(Product product)
 {
     try
     {
         if (string.IsNullOrEmpty(product.Name))
         {
             ErrorView error = new ErrorView()
             {
                 message = EmptyProductName
             };
             return(View("Error", error));
         }
         product.Specifications = GetSpecifications(product);
         var orignpics = GetPictures(product);
         product.OwnerID         = GetOwnerID();
         product.ProductPictures = orignpics;
         svc.Create(product);
         if (orignpics.Count > 0)
         {
             var newpics = new ProductPicture[orignpics.Count()];
             for (int i = 0; i < orignpics.Count(); i++)
             {
                 ProductPicture pic = new ProductPicture()
                 {
                     ID   = orignpics[i].ID,
                     Name = orignpics[i].Name,
                     Path = MakePath(product.ID.Value),
                 };
                 newpics[i] = pic;
             }
             svc.Update(newpics);
             _pictureService.Move(orignpics.ToArray(), newpics);
         }
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         ErrorView error = new ErrorView()
         {
             message = e.Message
         };
         return(View("Error", error));
     }
 }
Exemplo n.º 3
0
        private Collection <ProductPicture> GetUploadPictures(long productID)
        {
            Collection <ProductPicture> response = new Collection <ProductPicture>();

            for (int i = 0; i < Request.Files.Count; i++)
            {
                var            picFile = Request.Files[i];
                ProductPicture pic     = new ProductPicture();
                byte[]         buffer  = new byte[picFile.ContentLength];
                picFile.InputStream.Read(buffer, 0, picFile.ContentLength);
                pic.Content    = buffer;
                pic.OriginName = Path.GetFileName(picFile.FileName);
                pic.Name       = GetHashName(pic.OriginName);
                pic.Path       = MakePath(productID);
                pic.IsFirst    = false;
                pic.ProductID  = productID;
                response.Add(pic);
            }
            return(response);
        }
Exemplo n.º 4
0
        private Collection <ProductPicture> GetPictures(Product product)
        {
            int count = Convert.ToInt32(Request.Form["PicCount"]);
            Collection <ProductPicture> pictures = new Collection <ProductPicture>();

            for (int i = 0; i < count; i++)
            {
                if (!string.IsNullOrEmpty(Request.Form["picId" + i]))
                {
                    ProductPicture pic = new ProductPicture()
                    {
                        ID         = Convert.ToInt32(Request.Form["picId" + i]),
                        Name       = GetHashName(Request.Form["picName" + i]),
                        OriginName = Request.Form["picName" + i],
                        Path       = Request.Form["picPath" + i],
                        IsFirst    = Convert.ToBoolean(Request.Form["picIsFirst" + i]),
                        OwnerID    = product.OwnerID,
                        ProductID  = product.ID,
                    };
                    pictures.Add(pic);
                }
            }
            return(pictures);
        }