public static void UploadProduct(UploadedProduct product, string userId)
        {
            using (var DB = new ASPProjectDB())
            {
                byte[][] imgsbfr = new byte[3][];
                for (int i = 0; i < product.Images.Length; i++)
                {
                    int?length = product.Images[i]?.ContentLength;
                    imgsbfr[i] = length.HasValue ? new byte[length.Value] : null;
                    product.Images[i]?.InputStream.Read(imgsbfr[i], 0, imgsbfr[i].Length);
                }

                //var owner = DB.Users.Find(int.Parse(userId));
                Product p = new Product
                {
                    UploadingDate    = DateTime.Now,
                    Image1           = imgsbfr[0],
                    Image2           = imgsbfr[1],
                    Image3           = imgsbfr[2],
                    LongDescription  = product.LongDescription,
                    Price            = product.Price,
                    State            = ProductState.Available,
                    ShortDescription = product.ShortDescription,
                    Title            = product.Title,
                    OwnerId          = int.Parse(userId),
                };

                //owner.OwnedProducts.Add(p);
                DB.Products.Add(p);
                DB.SaveChanges();
            }
        }
예제 #2
0
 public ActionResult UploadProduct(UploadedProduct product)
 {
     if (ModelState.IsValid)
     {
         DataCollector.UploadProduct(product, Request.Cookies["user"]["userId"]);
         return(RedirectToRoute(new { controller = "Home" }));
     }
     return(View("AddProduct", product));
 }