// GET: BeerTasters/Details/5 public ActionResult Details(int beerid) { BeerWithRatingsDTO model = new BeerWithRatingsDTO(); //need to populate data here //potentially with viewbag for extra information return(View("BeerDataEntryView", model)); }
public void SaveBeer([FromBody] BeerWithRatingsDTO dto) { /// /// Load the string to RatingDTO /// To Query the List using the id /// If Found update, if not Insert /// }
public async Task SaveRating([FromBody] RatingDTO dto) { /// /// Persist RatingDTO /// To Query the existing data using the beerid /// If Found update, if not Insert /// var row = data.Where(x => x.id == dto.beerid).FirstOrDefault(); if (row == null) { BeerWithRatingsDTO temp = new BeerWithRatingsDTO(); temp.comments.Add(new RatingShortDTO() { username = dto.username, userrating = dto.userrating, comment = dto.comment }); /////////////////////// //Need to populate temp's Beer Information using Punk API!!!! /////////////////////// BeerDTO beer = await new PunkRepository().GetBeersById(dto.beerid); temp.name = beer.name; temp.description = beer.description; data.Add(temp); } else ////row!=null { var comment = row.comments.Where(x => x.username == dto.username).FirstOrDefault(); if (comment == null) { row.comments.Add(new RatingShortDTO() { username = dto.username, userrating = dto.userrating, comment = dto.comment }); } else { comment.username = dto.username; comment.userrating = dto.userrating; comment.comment = dto.comment; } } //persist the data back into File string newString = JsonConvert.SerializeObject(data, Formatting.Indented); File.WriteAllText("data.json", newString); /////////////////////// ///Need to ask BeerWithRatingsControler to reload! /////////////////////// BeerWithRatingsController.ReloadDataFromFile(); }