[HttpGet("clear/database")] // to clear the Json file - just for testing purpuse public ActionResult clearJsonData() { var beerSystem = new BeerSystem(_configs, _clientFactory); beerSystem.Clear(); return(Ok()); }
public async Task <ActionResult> Rate(int beerId, [FromBody] VoteModel voteData) { try { var beerSystem = new BeerSystem(_configs, _clientFactory); var result = await beerSystem.Rate(beerId, voteData); if (result) { return(Ok()); } else { return(StatusCode((int)HttpStatusCode.NotFound, new ValidationResultModel("beerId", "beerId not found."))); } } catch (Exception e1) { return(StatusCode((int)HttpStatusCode.InternalServerError, new ValidationResultModel(e1))); } }
public async Task <ActionResult> search(string keyword) { try { keyword = System.Web.HttpUtility.UrlDecode(keyword); var beerSystem = new BeerSystem(_configs, _clientFactory); var bearVotes = await beerSystem.Search(keyword); if (bearVotes != null && bearVotes.Count > 0) { // return Ok(bearVotes.toJson()); // use this if you want to return the Json response as text to be exactly like the provided example return(Ok(new JsonResult(bearVotes))); } else { return(StatusCode((int)HttpStatusCode.NotFound, new ValidationResultModel("No data found", "No data found."))); } } catch (Exception e1) { return(StatusCode((int)HttpStatusCode.InternalServerError, new ValidationResultModel(e1))); } }