public void AddWordAndExample(WordAndExampleDto dto) { _unitOfWork.BeginTransaction(); var description = dto.Description; var distinctedWords = WordUtils.ExtractDistinct(description); //var tokens = Regex.Split(dto.Description, "\r\n").Where(x => x.Trim() != string.Empty).ToArray(); //if (tokens.Length % 2 != 0) //{ // var errors = new List<string>() { "Khong the luu description" }; // throw new HttpResponseException(new HttpResponseMessage() { // Content = new StringContent("Khong the luu description"), StatusCode = HttpStatusCode.BadRequest }); //} var idxSub = description.Length > 200 ? description.Substring(0, 200) : description.Substring(0, description.Length / 2); var example = _exampleRepos.Create(new Example { Name = idxSub, Description = description, CreatedAt = DateTimeOffset.Now, Url = dto.Url }); var wordsInExample = CheckWords(distinctedWords); _unitOfWork.Save(); var newWordExample = wordsInExample.Select(x => new WordExample { ExampleId = example.Id, WordId = x.Id }); _wordExampleRepos.AddListWordExample(newWordExample); _unitOfWork.Save(); _unitOfWork.Commit(); }