Example #1
0
        public ActionResult Add(EntryModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(Ok(_entryService.Add(model)));
        }
Example #2
0
        public ActionResult Add(NewEntry model)
        {
            var entry = AutoMapper.Mapper.Map <Entry>(model);

            entry.PlayerId = SessionProfile.Player.Id;
            _entryService.Add(entry);

            SessionProfile.Player = _playerService.FindById(SessionProfile.Player.Id);

            return(RedirectToAction("Index", "Entry"));
        }
Example #3
0
 public IActionResult Entry(int blogId, [FromBody] EntryModel entryModel)
 {
     try
     {
         _entryService.Add(entryModel.ToDomainModel());
         return(CreatedAtAction("Get", new { id = entryModel.Id }, entryModel));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("AddEntry", ex.GetBaseException().Message);
         return(BadRequest(ModelState));
     }
 }
Example #4
0
        public async Task <ActionResult> Add(string userId, long journalId, EntryDto entryDto)
        {
            var result = await _service.Add(journalId, entryDto);

            if (result == null)
            {
                _logger.LogInformation($"Unable to add entry: {entryDto.Title}");
                return(BadRequest());
            }

            _logger.LogInformation($"Entry added: {entryDto.Id}");
            return(Created($"api/users/{userId}/journals/{journalId}/entries", result));
        }
Example #5
0
        public async Task <IActionResult> AddEntry(EntryCreationDto dto)
        {
            if (ModelState.IsValid)
            {
                var result = await _service.Add(dto);

                if (result != null)
                {
                    return(Ok(result));
                }

                return(BadRequest(new { Message = "Unable to add entry" }));
            }

            return(BadRequest(ModelState));
        }
Example #6
0
        public void Add_JournalFound_EntrySaved_ReturnsEntry()
        {
            // Arrange
            var newEntry = new NewEntry(
                _journal.UserId !, _journal.Id,
                "Spiffy New Entry",
                "gimme,some,reggae",
                "Axl Rose is the best evar");

            // Act
            var result = _service.Add(_journal, newEntry);

            // Assert
            result.Should().NotBeNull();
            result.Title.Should().Be(newEntry.Title);
        }
Example #7
0
        public async Task <Entry> AddEntry(long journalId, NewEntry newEntry)
        {
            using var unitOfWork = GetUnitOfWork();
            var journal = await unitOfWork
                          .Journals.Find(j => j.Id == journalId);

            if (journal is null)
            {
                throw new JournalNotFoundException($"Journal not found: {journalId}");
            }

            if (newEntry is null)
            {
                throw new ArgumentNullException(nameof(newEntry));
            }
            var entry = _entryService.Add(journal, newEntry);
            await unitOfWork.Complete();

            return(entry);
        }
Example #8
0
        public async Task GetAll()
        {
            await ArrangeTest();

            var journal = await _journalService.Add(_user.Id, "My Journal");

            await _entryService.Add(journal.Id, CreateEntryDto(_user, "My entry"));

            await _entryService.Add(journal.Id, CreateEntryDto(_user, "My other entry"));

            await _entryService.Add(journal.Id, CreateEntryDto(_user, "My other other entry"));

            var response = await _client.GetAsync(URL(_user.Id, journal.Id));

            response.EnsureSuccessStatusCode();
        }
Example #9
0
        public async Task <IActionResult> Add([FromBody] AddEntryDto addEntryDto)
        {
            await _entryService.Add(addEntryDto).ConfigureAwait(false);

            return(Ok());
        }