public ActionResult Edit(BLL.Model.NewsViewModelItem item) { if (!ModelState.IsValid) { return(View()); //TODO: return Error message in a little red window. } for (var i = 0; i < Request.Files.Count; i++) { var image = Request.Files[i]; if (image.ContentLength != 0) { byte[] imageData = null; using (var binaryReader = new BinaryReader(image.InputStream)) { imageData = binaryReader.ReadBytes(image.ContentLength); item.NewsImages.Add(new BLL.Model.NewsImageModelItem { NewsId = item.Id, ImageItem = imageData }); } } else { item.NewsImages = null; } } newsDbProv.Edit(item); return(RedirectToAction("Panel")); }
public ActionResult Create(BLL.Model.NewsViewModelItem item) { if (ModelState.IsValid || Request.Files.Count > 1) { ModelState["NewsImages"].Errors.Clear(); for (var i = 0; i < Request.Files.Count; i++) { var image = Request.Files[i]; byte[] imageData = null; using (var binaryReader = new BinaryReader(image.InputStream)) { imageData = binaryReader.ReadBytes(image.ContentLength); item.NewsImages.Add(new BLL.Model.NewsImageModelItem { NewsId = item.Id, ImageItem = imageData }); } } } else { TempData["Error"] = "The article wasn't published!"; return(View()); //TODO: return Error message in a little red window. } try { newsDbProv.Add(item); TempData["Success"] = "Added successfully!"; return(RedirectToAction("Edit", item.Id)); } catch { TempData["Error"] = "The article wasn't published!"; return(View()); } }