Exemplo n.º 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"));
            }
        }
Exemplo n.º 2
0
        public ActionResult Register(userCheck model)
        {
            if (model.UserDishes != null)
            {
                using (var dbTran = db.Database.BeginTransaction())
                {
                    try
                    {
                        int IdCheck = Convert.ToInt32(db.PR_NewCheck(model.CheckLocal.IdLocal).ToArray()[0]);
                        var lista   = model.UserDishes.Split(',').ToList();
                        foreach (var dishTmp in lista)
                        {
                            if (dishTmp != "")
                            {
                                db.PR_CreateDetailCheck(Convert.ToInt32(dishTmp), IdCheck);
                            }
                        }
                        var identity = (System.Web.HttpContext.Current.User as MyIdentity.MyPrincipal).Identity as MyIdentity;
                        db.PR_CreatePaymentCheck(identity.User.IdCard, IdCheck);
                        db.SaveChanges();
                        dbTran.Commit();

                        return(RedirectToAction("Index", "Checks"));
                    }
                    catch (Exception ex)
                    {
                        dbTran.Rollback();
                    }
                }
            }
            return(RedirectToAction("Create", "Checks", model));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "Code")] userCheck model)
        {
            Table requestTable = db.Table.Find(model.Code);

            if (requestTable != null)
            {
                model.CheckTable          = requestTable;
                model.CheckLocal          = requestTable.Local;
                model.CheckRestaurant     = requestTable.Local.Restaurant;
                model.DistrictCompeteName = _common.DistrictCompleteName(requestTable.Local.IdDistrict);
                model.UserDishes          = "";
                model.types = db.PR_GetTypes(requestTable.Local.Restaurant.IdRestaurant).Select(m => db.Type.Find(m)).ToList();
                return(View(model));
            }
            return(RedirectToAction("Invalid", "Checks"));
        }
Exemplo n.º 4
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());
 }
Exemplo n.º 5
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"));
        }
Exemplo n.º 6
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());
 }