Ejemplo n.º 1
0
        public async Task <IActionResult> CreateNoteForGroup(NoteForCreationDto noteForCreationDto)
        {
            var note = _mapper.Map <NoteForGroup>(noteForCreationDto);

            _repo.AddToRepo(note);
            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            throw new Exception("Nie udało się utworzyć newsa");
        }
Ejemplo n.º 2
0
        public ActionResult <NoteDto> CreateBookNote(Guid bookId, NoteForCreationDto note)
        {
            if (!_bookRepository.BookExists(bookId))
            {
                return(NotFound());
            }

            var noteEntity = _mapper.Map <Entities.Note>(note);

            _noteRepository.AddNote(bookId, noteEntity);
            _noteRepository.Save();

            var noteToReturn = _mapper.Map <NoteDto>(noteEntity);

            return(CreatedAtRoute("GetBookNote", new { bookId = bookId, noteId = noteToReturn.Id }, noteToReturn));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateNote(int userId, NoteForCreationDto noteForCreationDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            if (noteForCreationDto == null)
            {
                return(BadRequest());
            }
            noteForCreationDto.AuthorId = userId;
            var note = _mapper.Map <Note> (noteForCreationDto);

            _repo.Add(note);

            if (await _repo.SaveAll())
            {
                var noteToReturn = _mapper.Map <NoteToReturnDto> (note);
                return(CreatedAtRoute("GetNote", new { id = note.Id }, noteToReturn));
            }

            throw new Exception("Błąd przy zapisywaniu");
        }