public async Task <IHttpActionResult <AdjectiveDto> > Post([FromBody] AdjectiveDto adjDto) { try { Adjective adj = new Adjective { Value = adjDto.Value, ModificationDate = DateTime.Now }; if (await _adjService.ExistsAsync(adj)) { return(BadRequest <AdjectiveDto>("Entry already exists")); } else { adj = await _adjService.CreateAsync(adj); return(Ok(adj.ToAdjectiveDto())); } } catch { return(InternalServerError <AdjectiveDto>(new AdjectiveDto())); } }
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.")); } }