コード例 #1
0
        public void Create(MainImageViewModel model)
        {
            foreach (var element in GetAllPerProductId(model.ProductId))
            {
                if (model.MainPicture)
                { element.MainPicture = false; }
                else
                { break; }
            }

            Image picture = new Image
            {
            ImageId= model.ImageId,
            ProductId = model.ProductId,
            FileName = model.FileName,
            Picture = new byte [model.Image.ContentLength],
            ImageMineType = model.Image.ContentType,
            MainPicture = model.MainPicture
            };

            using (MemoryStream memStream = new MemoryStream(model.Image.ContentLength))
            {
                // model.Image.InputStream.Read(picture.Picture,0, model.Image.ContentLength);
                model.Image.InputStream.CopyTo(memStream, model.Image.ContentLength);
                picture.Picture = memStream.ToArray();
            }
            using (var context = new WebShopMVCContext())
            {
                 context.Images.Add(picture);
                 context.SaveChanges();
            }
        }
コード例 #2
0
 public ActionResult Create(MainImageViewModel model)
 {
     if (ModelState.IsValid)
     {
         imageService.Create(model);
         return RedirectToAction("List", "Image");
     }
     return View(model);
 }
コード例 #3
0
 public ActionResult Create(int Id)
 {
     var model = new MainImageViewModel();
     model.ProductId = Id;
     return View(model);
 }