Exemplo n.º 1
0
        public IActionResult Add(NoteForAddingDto noteDto)
        {
            var noteToAdd = _mapper.Map <Note>(noteDto);

            _repo.Add(noteToAdd);

            return(Ok());
        }
        public void EFRepository_AddNote_ValidCall()
        {
            List <Note> listOfNotes = CreateTestData.GetListOfNotes();
            var         mockSet     = new Mock <DbSet <Note> >()
                                      .SetupData(listOfNotes, o =>
            {
                return(listOfNotes.Single(x => x.Note_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                var expected = CreateTestData.GetSampleNote();
                var id       = Guid.Parse("b346eee6-eba7-4ea7-be2e-911bb9034233");
                expected.Note_id = id;

                mockContext.Mock <CharacterContext>()
                .Setup(x => x.Set <Note>()).Returns(mockSet.Object);

                //Act
                INotesRepository toTest = mockContext.Create <NotesRepository>();
                toTest.Add(expected);
                var actual = toTest.Get(id);

                //Assert
                actual.Should().NotBeNull();
                expected.Should().NotBeNull();
                actual.Should().BeOfType <Note>();
                expected.Should().BeOfType <Note>();
                actual.Should().BeEquivalentTo(expected);
            }
        }
Exemplo n.º 3
0
 public void AddOrUpdate(NoteDTO newNote)
 {
     if (newNote.ID == 0)
     {
         _notesRepository.Add(newNote.ToNoteModel());
     }
     else
     {
         _notesRepository.Update(newNote.ToNoteModel());
     }
 }
Exemplo n.º 4
0
        public ActionResult <Note> Add([FromBody] NoteDtoAdd model)
        {
            var result = _notesRepository.Add(model);

            if (result == null)
            {
                BadRequest();
            }

            return(Ok(result));
        }
        public IActionResult Post([FromBody] Note note)
        {
            if (note == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }

            repository.Add(note);

            return(CreatedAtAction("Get", new { id = note.NoteId }, note));
        }
Exemplo n.º 6
0
        public async Task <OkResult> AddAsync()
        {
            string body = await new StreamReader(Request.Body, Encoding.UTF8).ReadToEndAsync();
            Note   note = new Note()
            {
                content = body
            };

            _notesRepository.Add(note);
            return(Ok());
        }
        public async Task <IActionResult> PostNote(Note note)
        {
            // prefill userid and have todays date put on for the note that's created today
            note.UserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            DateTime thisDay = DateTime.Now;
            string   NowDate = thisDay.ToString("g");

            note.DateCreated = Convert.ToDateTime(NowDate);

            _repo.Add(note);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Failed to save Notes"));
        }
 public Note Add(NoteDtoAdd model) => _notesRepository.Add(model);