예제 #1
0
        public async Task <ActionResult> Store([FromBody] NoteViewModel model)
        {
            ValidateRequest(model);
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var note = model.MapEntity(_mapper, CurrentUserId);

            note = await _notesService.CreateAsync(note);

            if (model.Attachments.HasItems())
            {
                var attachments = model.Attachments.Select(item => item.MapEntity(_mapper, CurrentUserId)).ToList();
                foreach (var attachment in attachments)
                {
                    attachment.PostType = PostType.Note;
                    attachment.PostId   = note.Id;
                }

                _attachmentsService.CreateMany(attachments);

                note.Attachments = attachments;
            }


            return(Ok(note.MapViewModel(_mapper)));
        }
예제 #2
0
        public async Task <NoteDto> Create()
        {
            var note  = JsonConvert.DeserializeObject <NoteDto>(Request.Form["note"]);
            var files = Request.Form.Files;

            var photoDtos = new List <PhotoDto>();

            if (files != null)
            {
                foreach (var file in files)
                {
                    if (file.Length <= 0)
                    {
                        continue;
                    }
                    byte[] buffer;
                    using (var ms = new MemoryStream())
                    {
                        file.CopyTo(ms);
                        buffer = ms.ToArray();
                    }

                    var photoDto = new PhotoDto
                    {
                        Name    = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'),
                        Content = Convert.ToBase64String(buffer)
                    };
                    photoDtos.Add(photoDto);
                }
            }
            note.Photos = photoDtos;
            return(await _notesService.CreateAsync(note));
        }
예제 #3
0
        public async Task <IActionResult> Post([FromBody] NoteViewModel note)
        {
            await _service.CreateAsync(note);

            return(Ok());
        }