예제 #1
0
        public async Task <IActionResult> CreateNote([FromBody] NoteViewModel noteViewModel)
        {
            if (noteViewModel == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Note note = new Note
            {
                Id           = Guid.NewGuid(),
                Title        = noteViewModel.Title,
                Message      = noteViewModel.Message,
                DateCreated  = noteViewModel.DateCreated,
                LastModified = noteViewModel.LastModified
            };

            bool isSuccess = await _notesService.AddNotesAsync(note);

            if (isSuccess)
            {
                return(Created(string.Empty, null));
            }
            else
            {
                return(new ObjectResult("Failed to create notes"));
            }
        }