コード例 #1
0
        public async Task <IActionResult> UpdateUser([FromRoute] int id, [FromBody] databaseInputUser objUser)
        {
            if (objUser == null || id != objUser.userId)
            {
                return(new JsonResult("This User cannot be updated"));
            }
            else
            {
                userPref up = new userPref();
                up.user_id     = id;
                up.craft_slide = objUser.craftSlide;
                up.complexity  = objUser.Complexity;
                up.price_range = objUser.PriceRange;
                _db.user_pref.Update(up);
                userCheck uc = new userCheck();
                uc.user_id = objUser.userId;
                uc.wine    = objUser.WineCheck;
                uc.beer    = objUser.BeerCheck;
                uc.spirit  = objUser.SpiritCheck;
                _db.user_check.Update(uc);
                await _db.SaveChangesAsync();

                return(new JsonResult("User has been updated"));
            }
        }
コード例 #2
0
 public IActionResult getUserPref([FromRoute] int id)
 {
     if (_db.users.Find(id) != null)
     {
         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;
         return(Ok(user));
     }
     return(NotFound());
 }
コード例 #3
0
        public async Task <IActionResult> AddUsers([FromBody] databaseInputUser objUsers)
        {
            // Checks if the model structure is fully valid otherwise it will return that it is not valid.
            if (!ModelState.IsValid)
            {
                return(new JsonResult("Error While Creating New User"));
            }
            // Adds the user inputted into the database
            Users u = new Users();

            u.userName = objUsers.userName;
            u.Password = objUsers.Password;
            _db.users.Add(u);
            await _db.SaveChangesAsync();

            Users    user = _db.users.Find(u.userId);
            int      id   = user.userId;
            userPref up   = new userPref();

            up.user_id     = id;
            up.craft_slide = objUsers.craftSlide;
            up.complexity  = objUsers.Complexity;
            up.price_range = objUsers.PriceRange;
            _db.user_pref.Add(up);
            await _db.SaveChangesAsync();

            userCheck uc = new userCheck();

            uc.user_id = id;
            uc.wine    = objUsers.WineCheck;
            uc.beer    = objUsers.BeerCheck;
            uc.spirit  = objUsers.SpiritCheck;
            _db.user_check.Add(uc);
            // Waits and makes sure the database saves the changes
            await _db.SaveChangesAsync();

            // Returns to the front end that the user has been inserted into the bar.
            return(new JsonResult("User inserted successfully"));
        }
コード例 #4
0
 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());
 }