public async Task <IActionResult> DeleteSuggestion([FromBody] SuggestionReqModel model) { try { await this.service.DeleteSuggestion(model); } catch (NotFoundException e) { return(this.BadRequest(e.Message)); } return(this.Ok()); }
internal async Task DeleteSuggestion(SuggestionReqModel model) // fix this shit { if (model.Type == "Court") { var sug = this.context.Court.FirstOrDefault(x => x.Name == model.Name && x.Jurisdiction.JurCode == model.JurCode); if (sug != null) { this.context.Court.Remove(sug); } } else if (model.Type == "CourtEng") { var sug = this.context.CourtEng.FirstOrDefault(x => x.Name == model.Name && x.Jurisdiction.JurCode == model.JurCode); if (sug != null) { this.context.CourtEng.Remove(sug); } } else if (model.Type == "Source") { var sug = this.context.Source.FirstOrDefault(x => x.Name == model.Name && x.Jurisdiction.JurCode == model.JurCode); if (sug != null) { this.context.Source.Remove(sug); } } else if (model.Type == "Keywords") { var sug = new Keyword { Name = model.Name }; this.context.Remove(sug); } else { throw new NotFoundException("Type not found!"); } await this.context.SaveChangesAsync(); }