public ActionResult Wijzig(Nieuws nieuws, HttpPostedFileBase file) { try { Nieuws oldNieuws = nieuwsManager.GetNieuws(nieuws.ID); byte[] imgByte; if (file != null && file.ContentLength > 0) { using (MemoryStream ms = new MemoryStream()) { file.InputStream.CopyTo(ms); imgByte = ms.GetBuffer(); Image a = byteArrayToImage(imgByte); a = Resize(a, 1920, 1080); imgByte = imageToByteArray(a); } nieuws.groteAfbeelding = imgByte; } else { nieuws.groteAfbeelding = oldNieuws.groteAfbeelding; } // TODO: Add update logic here nieuws.datum = oldNieuws.datum; nieuwsManager.ChangeNieuws(nieuws); return RedirectToAction("Lijst"); } catch { return View(); } }
public ActionResult Nieuw() { Nieuws nieuws = new Nieuws(); nieuws.statusOnline = true; return View(nieuws); }
public ActionResult Nieuw(Nieuws nieuws, HttpPostedFileBase file) { try { byte[] imgByte; if (file != null && file.ContentLength > 0) { using (MemoryStream ms = new MemoryStream()) { file.InputStream.CopyTo(ms); imgByte = ms.GetBuffer(); Image a = byteArrayToImage(imgByte); a = Resize(a, 1920, 1080); imgByte = imageToByteArray(a); } } else { Image image = Image.FromFile(Path.Combine(Server.MapPath("/Images/logo/"), "default.png")); using (MemoryStream ms = new MemoryStream()) { MemoryStream ms2 = new MemoryStream(); image.Save(ms2, System.Drawing.Imaging.ImageFormat.Png); imgByte = ms2.ToArray(); } } // TODO: Add insert logic here nieuws.groteAfbeelding = imgByte; nieuws.adminNaam = User.Identity.Name; nieuws.datum = DateTime.Now; nieuwsManager.CreateNieuws(nieuws); return RedirectToAction("Lijst"); } catch { return View(); } }
//UPDATE public void UpdateNieuws(Nieuws nieuws) { Nieuws oldNieuws = db.nieuws.Find(nieuws.ID); db.Entry(oldNieuws).CurrentValues.SetValues(nieuws); db.SaveChanges(); }
//CREATE public Nieuws CreateNieuws(Nieuws nieuws) { db.nieuws.Add(nieuws); db.SaveChanges(); return nieuws; }
//CREATE public Nieuws CreateNieuws(Nieuws nieuws) { return mapper.CreateNieuws(nieuws); }
//CHANGE public void ChangeNieuws(Nieuws nieuws) { mapper.UpdateNieuws(nieuws); }