public async Task <IActionResult> DeleteParserWord(string name) { if (!ModelState.IsValid || string.IsNullOrEmpty(name)) { return(BadRequest(new { status = StatusCodes.Status400BadRequest, message = "Request is not correct." })); } try { ParserWord parserWord = await Task.Run(() => _wordService.DeleteParserWord(name)); ParserWordDTO parserWordDTO = _mapper.Map <ParserWordDTO>(parserWord); return(Ok(new { status = StatusCodes.Status200OK, message = $"The <{name}> ParserWord record is deleted.", data = parserWordDTO })); } catch (Exception ex) { return(BadRequest(new { status = StatusCodes.Status400BadRequest, message = ex.Message })); } }
public ParserWord GetParserWord(string name) { if (String.IsNullOrEmpty(name)) { _logger.Warn(ERR_ARG_NULL_EXP_GET); _logger.Warn(EXP_GENERATED); throw new ArgumentNullException(ERR_ARG_NULL_EXP_GET); } _logger.Info("Attempt to get \"{name}\" record from the ParserWords table occured."); ParserWord parserWord = _unitOfWork.ParserWords.Get(name); if (parserWord == null) { _logger.Info($"There is no ParserWord record with \"{name}\" in the ParserWords table."); return(null); } _logger.Info("Attempt to get \"{name}\" record from ParserWords table succeeded."); return(parserWord); }
public async Task <IActionResult> AddParserWord([FromBody] ParserWordDTO word) { if (!ModelState.IsValid || word == null) { return(BadRequest(new { status = StatusCodes.Status400BadRequest, message = "WordParserDTO request object is not correct." })); } try { ParserWord parserWord = _mapper.Map <ParserWord>(word); await Task.Run(() => _wordService.AddParserWord(parserWord)); return(Ok(new { status = StatusCodes.Status201Created, message = "The new record of the ParserWords table was successfully added.", data = word })); } catch (Exception ex) { return(BadRequest(new { status = StatusCodes.Status400BadRequest, message = ex.Message })); } }
public void AddParserWord(ParserWord word) { if (word == null || string.IsNullOrEmpty(word.Name)) { return; } _unitOfWork.ParserWords.Create(word); _unitOfWork.Save(); }
public void InsertOrUpdateParserWord(ParserWord word) { if (word == null || string.IsNullOrEmpty(word.Name)) { return; } _unitOfWork.ParserWords.InsertOrUpdate(word); _unitOfWork.Save(); }
public IEnumerable <ParserWordDTO> AddParserWordsFromRow(SubtitleRow row) { if (row == null || string.IsNullOrEmpty(row.Value)) { return(null); } string[] words; List <ParserWordDTO> wordsDto = new List <ParserWordDTO>(); List <ParserWord> wordsToCreate = new List <ParserWord>(); if (TryParseWords(row.Value, out words)) { string language = row.LanguageName; int subtitleRowId = row.Id; foreach (string word in words) { ParserWord newWord = new ParserWord { Name = word, LanguageName = language, SubtitleRowId = subtitleRowId }; wordsToCreate.Add(newWord); ParserWordDTO newWordDto = new ParserWordDTO() { Name = word, LanguageName = language, SubtitleRowId = subtitleRowId }; wordsDto.Add(newWordDto); } AddRangeParserWords(wordsToCreate); IEnumerable <ParserWordDTO> results = (IEnumerable <ParserWordDTO>)wordsDto; return(results); } return(null); }
public static void InitializeParserWords(IApplicationBuilder applicationBuilder) { IUnitOfWorkParser context = applicationBuilder.ApplicationServices.GetRequiredService <IUnitOfWorkParser>(); if (context.ParserWords.Any()) { return; } var parserWords = new ParserWord[] { new ParserWord { Name = "car" }, new ParserWord { Name = "time" }, new ParserWord { Name = "beatiful" }, new ParserWord { Name = "flower" }, new ParserWord { Name = "clean" }, new ParserWord { Name = "rain" }, new ParserWord { Name = "table" }, new ParserWord { Name = "strong" }, }; foreach (ParserWord word in parserWords) { context.ParserWords.Create(word); } context.Save(); }
public async Task <IActionResult> GetParserWord(string name) { _logger.Info($"GET Action: Attempt to get ParserWord record by \"{name}\""); if (!ModelState.IsValid) { _logger.Error("ModelState is not valid."); _logger.Error("400 StatusCode is generated."); return(BadRequest(BaseStatusDto.CreateErrorDto("Bad request. Model state is not valid."))); } try { _logger.Debug("Call ParserWordService for the request handling."); ParserWord word = _wordService.GetParserWord(name); if (word == null) { _logger.Debug("The ParserWord record with Name = \"{name}\" is not found."); _logger.Debug("404 StatusCode is generated."); return(NotFound(BaseStatusDto.CreateErrorDto(ERR_ID_NOT_FOUND + $"\"{name}\""))); } _logger.Debug("The ParserWord record with Name = \"{name}\" is found."); _logger.Info("Database record from ParserWords is safely returned to the client side."); _logger.Debug("200 StatusCode is generated."); ParserWordDTO wordDTO = _mapper.Map <ParserWordDTO>(word); wordDTO.CreateSuccess("GET request succeeds."); return(Ok(wordDTO)); } catch (Exception ex) { _logger.Error($"{ex.GetType()} exception is generated."); _logger.Error($"{ex.Message}"); return(BadRequest(BaseStatusDto.CreateErrorDto(ex.Message))); } }
public ParserWord DeleteParserWord(string name) { if (String.IsNullOrEmpty(name)) { return(null); } ParserWord parserWord = _unitOfWork.ParserWords.Get(name); if (parserWord == null) { throw new ArgumentNullException("The ParserWord entity does not exist in the database."); } _unitOfWork.ParserWords.Delete(parserWord); _unitOfWork.Save(); return(parserWord); }
public async Task <IActionResult> PutInsertOrUpdateParserWord([FromBody] ParserWordDTO word) { if (!ModelState.IsValid || word == null) { return(BadRequest(BaseStatusDto.CreateErrorDto("WordParserDTO request object is not correct."))); } try { ParserWord parserWord = _mapper.Map <ParserWord>(word); await Task.Run(() => _wordService.InsertOrUpdateParserWord(parserWord)); ParserWordDTO parserWordDto = _mapper.Map <ParserWordDTO>(parserWord); return(Ok(parserWordDto)); } catch (Exception ex) { return(BadRequest(BaseStatusDto.CreateErrorDto(ex.Message))); } }