public void AddNote(int userId, AddNoteForm addNoteForm)
        {
            Note note = new Note();

            note.UserId      = userId;
            note.Title       = addNoteForm.Title;
            note.Content     = addNoteForm.Content;
            note.Anniversary = addNoteForm.Anniversary;
            note.Hidden      = addNoteForm.Hidden;
            note.Alarm       = addNoteForm.Alarm;

            _context.Add(note);
        }
示例#2
0
        public async Task <IActionResult> AddNoteByToken([FromForm] AddNoteForm addNoteForm, List <IFormFile> images)
        {
            var id = GetIdByToken(this);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_userService.UserExistsById(id))
            {
                return(NotFound(new Response("404", "User not found!")));
            }

            _noteService.AddNote(id, addNoteForm);
            await _context.SaveChangesAsync();

            _noteImageService.AddListImage(_noteService.GetNewestNote(id), images);
            await _context.SaveChangesAsync();

            return(Ok(new Response("200", "Successfully added!")));
        }