示例#1
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();
        }
示例#2
0
        public async void AddJournal(int interventionId, JournalDto journalDto)
        {
            var newJournal = _mapper.Map <Journal>(journalDto);

            newJournal.InterventionId = interventionId;
            _journalService.Add(newJournal);
            await _interventionHub.Clients.All.SendAsync("journalUpdated", interventionId, newJournal.Id);
        }
示例#3
0
 public IHttpActionResult SaveJournal(Journal model)
 {
     if (string.IsNullOrEmpty(model.Id))
     {
         return(Ok(_service.Add(model)));
     }
     else
     {
         return(Ok(_service.Update(model)));
     }
 }
示例#4
0
        public async Task <ActionResult> Add(string userId, NewJournalDto newJournal)
        {
            var journal = await _service.Add(userId, newJournal.Title);

            if (journal == null)
            {
                _logger.LogInformation($"Unable to add journal with title: {newJournal.Title}");
                return(BadRequest());
            }

            _logger.LogInformation($"Journal added: {newJournal.Title}");
            return(Ok(journal));
        }
        public async Task GetOne()
        {
            await ArrangeTest();

            var journal = await _service.Add(_user.Id, "Super Duper Journal");

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

            response.EnsureSuccessStatusCode();
        }
示例#6
0
        public async Task <IActionResult> Add(NewJournal newJournal)
        {
            PrepJournalServiceWithUserId();
            JournalDto journal;

            try
            {
                journal = (await _journalService.Add(newJournal)).ToDto();
            }
            catch (ArgumentNullException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (UserNotFoundException ex)
            {
                return(NotFound(ex.Message));
            }

            return(CreatedAtAction(nameof(Add), journal));
        }
        public async Task <IActionResult> Post([FromForm] JournalViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                if (_journalService.IfJournalAlreadyExist(model.Title))
                {
                    throw new DuplicateNameException("Duplicate Entry");
                }
                var fileUploadPath = Path.Combine(_hostingEnvironment.WebRootPath, "upload/thesisFile");
                model.ThesisFileUrl = await _uploadService.FileUploader(model.ThesisFile, fileUploadPath);

                await _journalService.Add(model);

                return(Ok(model));
            }
            catch (Exception e)
            {
                return(BadRequest("Cannot connect to the server at the moment, try again"));
            }
        }