public async Task <ResponseApi> Handle(CreateListLanguagesCommand request, CancellationToken cancellationToken) { try { int invalidQty = 0; foreach (var language in request.Languages) { language.Validate(); if (language.Invalid) { invalidQty += 1; } if (invalidQty > 0) { return(new ResponseApi(false, "Something is wrong...", language.Notifications)); } } List <LanguageViewModel> result = new List <LanguageViewModel>(); for (int i = 0; i < request.Languages.Count; i++) { request.Languages[i].IdUser = request.IdUser; Language language = _mapper.Map <Language>(request.Languages[i]); await _languageRepository.Insert(language); var createResult = new LanguageViewModel { Id = language.Id, LanguageName = language.LanguageName, LanguageUnderstanding = language.LanguageUnderstanding, LanguageWriting = language.LanguageWriting, LanguageSpeaking = language.LanguageSpeaking, Active = language.Active, Excluded = language.Excluded, CreationDate = language.CreationDate, LastUpdate = language.LastUpdate, IdUser = language.IdUser }; result.Add(createResult); } return(new ResponseApi(true, "Languages created sucessfuly.", result)); } catch (Exception e) { return(new ResponseApi(false, "Error...", e)); } }
public async Task <IActionResult> CreateLanguage([FromBody] CreateListLanguagesCommand createCompetence) { var result = await _mediator.Send(createCompetence); return(Ok(result)); }