public async Task <bool> ParseDataFromFile(IFormFile file) { try { using (var stream = new MemoryStream()) { await file.CopyToAsync(stream); var dataInBytes = stream.ToArray(); var decodoedData = Encoding.Default.GetString(dataInBytes); var parsedData = JsonConvert.DeserializeObject <Character[]>(decodoedData); foreach (var character in parsedData) { await _characterService.CreateAsync(character); } return(true); } } catch { return(false); } }
public async Task <IActionResult> CreateCharacter([FromBody] CharacterCreateDto dto) { var character = await _characterService.CreateAsync(dto); var characterDto = new CharacterDto(character); return(Ok(characterDto)); }
public async Task <IActionResult> PostAsync([FromBody] CharacterDto characterDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Created("", await _characterService.CreateAsync(characterDto))); }
public async Task <IActionResult> Create([Bind("Character, SelectedSpeciesId")] CharacterViewModel characterViewModel) { if (ModelState.IsValid) { var selectedSpecies = await _speciesService.GetByIdAsync(characterViewModel.SelectedSpeciesId); characterViewModel.Character.Species = selectedSpecies; await _characterService.CreateAsync(characterViewModel.Character); return(RedirectToAction(nameof(Index))); } characterViewModel.Species = await _speciesService.GetAsync(); return(View(characterViewModel)); }
public async Task CreateAsync(CreateCharacterRequest request) => await _service.CreateAsync(request);