public async Task <IHttpActionResult <NounDto> > Post([FromBody] NounDto nounDto) { try { Noun noun = new Noun { Value = nounDto.Value, ModificationDate = DateTime.Now }; if (await _nounService.ExistsAsync(noun)) { return(BadRequest <NounDto>("Entry already exists")); } else { noun = await _nounService.CreateAsync(noun); return(Ok(noun.ToNounDto())); } } catch { return(InternalServerError <NounDto>(new NounDto())); } }
public async Task <IHttpActionResult <string> > Import([FromBody] DataDto data) { try { int importedAdj = 0; int importedNoun = 0; foreach (AdjectiveReadDto adjDto in data.Adjectives) { Adjective adj = new Adjective { Value = adjDto.Value, CreationDate = DateTime.Now, ModificationDate = DateTime.Now }; await _adjService.CreateAsync(adj); importedAdj++; } foreach (NounReadDto nounDto in data.Nouns) { Noun noun = new Noun { Value = nounDto.Value, CreationDate = DateTime.Now, ModificationDate = DateTime.Now }; await _nounService.CreateAsync(noun); importedNoun++; } return(Ok <string>("Imported " + importedAdj + " adjective(s) and " + importedNoun + " noun(s).")); } catch { return(InternalServerError <string>("Could not import.")); } }