private void ReadImage(NoteCreateVM note) { if (Request.Files["ImageData"] != null) { using (var memory = new BinaryReader(Request.Files["ImageData"].InputStream)) { var data = memory.ReadBytes((int)Request.Files["ImageData"].InputStream.Length); note.ImageData = data; note.MimeTypeImage = Request.ContentType; } } }
public ActionResult AddPost(NoteCreateVM note) { if (!ModelState.IsValid) { ViewBag.Notes = _noteModels.GetAll(); return(View("Index", note)); } ReadImage(note); _noteModels.Add(note); return(RedirectToAction("index")); }
public Guid Add(NoteCreateVM note) { var currentImage = new Image() { Data = note.ImageData, MimeType = note.MimeTypeImage, }; var idImage = _images.Add(currentImage); var currentNote = new Note() { Text = note.Text, ImageId = idImage, }; return(_notes.Add(currentNote)); }
public ActionResult AddPost(NoteCreateVM noteVm) { if (!ModelState.IsValid) { ViewBag.Notes = _noteLogic.GetAll(); return(View("Index", noteVm)); } var image = ReadImage(); var note = new Note { Text = noteVm.Text }; _noteLogic.Add(note, image); return(RedirectToAction("index")); }