Пример #1
0
        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;
                }
            }
        }
Пример #2
0
        public ActionResult AddPost(NoteCreateVM note)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Notes = _noteModels.GetAll();

                return(View("Index", note));
            }

            ReadImage(note);
            _noteModels.Add(note);
            return(RedirectToAction("index"));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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"));
        }