public async Task DeleteWord(ProhibitedWordModel model) { var item = DataMapper.Map <ProhibitedName, ProhibitedWordModel>(model); await Task.Run(() => repo.Delete(item)); await searchService.RemoveProhibitedNameAsync(item); }
public async Task UpdateWord(ProhibitedWordModel model) { var item = repo.Query().Where(x => x.Id == model.Id).FirstOrDefault(); await searchService.RemoveProhibitedNameAsync(item); item.Word = model.Word; await Task.Run(() => repo.Update(item)); await searchService.InsertProhibitedNameAsync(new ProhibitedName { Id = item.Id, Word = item.Word }); }
public async Task <IActionResult> Delete([FromBody] ProhibitedWordModel value) { try { await service.DeleteWord(value); return(Ok()); } catch { return(NotFound()); } }
public async Task <IActionResult> Post([FromBody] ProhibitedWordModel value) { try { await service.InsertWord(value); return(Ok()); } catch (ArgumentException ex) { return(BadRequest(ex.Message)); } }
public async Task InsertWord(ProhibitedWordModel model) { if (await repo.WordExists(model.Word)) { throw new ArgumentException("This word already exists"); } var item = DataMapper.Map <ProhibitedName, ProhibitedWordModel>(model); var xr = await Task.Run(() => repo.Insert(new ProhibitedName { Word = model.Word })); await searchService.InsertProhibitedNameAsync(xr); }