public async Task <IActionResult> AddBar([FromBody] databaseInputBars objBars) { // Checks if the model is valid from the body and returns that this is incorrect if (!ModelState.IsValid) { return(new JsonResult("Error While Creating New Bar")); } Bars b = new Bars(); b.bar_name = objBars.barName; b.street_num = objBars.street_num; b.street_name = objBars.street_name; b.suburb = objBars.suburb; b.city = objBars.city; // Adds the bar to the database if this is correct. _db.bars.Add(b); await _db.SaveChangesAsync(); Bars bar = _db.bars.Find(b.barId); int id = b.barId; barScore bs = new barScore(); bs.bar_id = id; bs.craft_slide = objBars.craftSlide; bs.complexity = objBars.complexity; bs.lqBeer = objBars.lqBeer; bs.lqMeal = objBars.lqMeal; bs.uqBeer = objBars.uqBeer; bs.uqMeal = objBars.uqMeal; _db.bar_score.Add(bs); await _db.SaveChangesAsync(); barCheck bc = new barCheck(); bc.bar_id = id; bc.wine = objBars.wineCheck; bc.beer = objBars.beerCheck; bc.spirit = objBars.spiritCheck; _db.bar_check.Add(bc); // Waits and checks that the changes are saved within the database. await _db.SaveChangesAsync(); // Returns that the Bar has been inserted into the database. return(new JsonResult("Bar inserted successfully")); }
public IActionResult getPrefBar([FromRoute] int id) { if (_db.users.Find(id) != null) { K_Nearest_Neighbour knn = new K_Nearest_Neighbour(); Users u = _db.users.Find(id); userPref up = _db.user_pref.Find(id); userCheck uc = _db.user_check.Find(id); databaseInputUser user = new databaseInputUser(); user.craftSlide = up.craft_slide; user.Complexity = up.complexity; user.PriceRange = up.price_range; user.WineCheck = uc.wine; user.BeerCheck = uc.beer; user.SpiritCheck = uc.spirit; int bbid = 0; foreach (Bars b in _db.bars.ToArray()) { int currentID = b.barId; barScore bs = _db.bar_score.Find(currentID); barCheck bc = _db.bar_check.Find(currentID); databaseInputBars db = new databaseInputBars(); db.bar_id = b.barId; db.craftSlide = bs.craft_slide; db.complexity = bs.complexity; db.lqBeer = (int)bs.lqBeer; db.lqMeal = (int)bs.lqMeal; db.uqBeer = (int)bs.uqBeer; db.uqMeal = (int)bs.uqMeal; db.beerCheck = bc.beer; db.wineCheck = bc.wine; db.spiritCheck = bc.spirit; bbid = knn.testing(user, db); } return(Ok(_db.bars.Find(bbid))); } return(NotFound()); }
public async Task <IActionResult> UpdateBar([FromRoute] int id, [FromBody] databaseInputBars objBars) { if (objBars == null || _db.bars.Find(id) != null) { return(new JsonResult("This Bar cannot be updated")); } else { Bars b = new Bars(); b.barId = id; barScore bs = new barScore(); barCheck bc = new barCheck(); b.bar_name = objBars.barName; b.street_num = objBars.street_num; b.street_name = objBars.street_name; b.suburb = objBars.suburb; b.city = objBars.city; bs.bar_id = id; bs.craft_slide = objBars.craftSlide; bs.complexity = objBars.complexity; bs.lqBeer = objBars.lqBeer; bs.lqMeal = objBars.lqMeal; bs.uqBeer = objBars.uqBeer; bs.uqMeal = objBars.uqMeal; bc.bar_id = id; bc.beer = objBars.beerCheck; bc.wine = objBars.wineCheck; bc.spirit = objBars.spiritCheck; _db.bars.Update(b); _db.bar_score.Update(bs); _db.bar_check.Update(bc); await _db.SaveChangesAsync(); return(new JsonResult("Bar has been updated")); } }