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(); } }
public ActionResult Create(MainImageViewModel model) { if (ModelState.IsValid) { imageService.Create(model); return RedirectToAction("List", "Image"); } return View(model); }
public ActionResult Create(int Id) { var model = new MainImageViewModel(); model.ProductId = Id; return View(model); }