Пример #1
0
        public Boolean edit(user user)
        {
            UserIM im = new UserIM(db);
            user dbVersion =im.find(user.id);
            if (dbVersion.version == user.version)
            {
                user.current_table_id = dbVersion.current_table_id;

                // If password was blank (only editing details) make sure we keep it the same
                if (user.password == null)
                {
                    user.password = dbVersion.password;
                    user.ConfirmPassword = user.password;
                }

                // If the user's role is null (happens if the user is editing his/her own details)
                if (user.user_role == null)
                    user.user_role = dbVersion.user_role;

                ((IObjectContextAdapter)db).ObjectContext.Detach(dbVersion);
                db.Entry(user).State = EntityState.Modified;

                user.version = user.version + 1;
                db.SaveChanges();
                return true;
            }
            return false;
        }
Пример #2
0
        public ActionResult Assign(string id)
        {
            UserIM uim = new UserIM(db);
            Util.Security.AES aes = new Util.Security.AES();
            int tableId = Int16.Parse(aes.DecryptString(id));
            table tab = im.find(tableId);
            user authUser = Util.User.UserUtil.getAuthenticatedUser(Request);

            if (authUser == null)
            {
                return RedirectToAction("LogOn", "User");
            }

            user dbUser = uim.find(authUser.id);
            dbUser.current_table_id = tab.id;

            // TODO: This is a hack, the User crud is broken.
            dbUser.ConfirmPassword = dbUser.password;
            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }

            return RedirectToAction("UserMenu", "Menu");
        }
Пример #3
0
        public static user getAuthenticatedUser(HttpRequestBase requestBase)
        {
            try
            {
                db = new touch_for_foodEntities();
                HttpCookie formsCookie = requestBase.Cookies[FormsAuthentication.FormsCookieName];
                FormsAuthenticationTicket auth = FormsAuthentication.Decrypt(formsCookie.Value);
                int userID = int.Parse(auth.UserData);

                UserIM im = new UserIM();
                return im.find(userID);
            }
            catch (Exception)
            {
                return null;
            }
        }
Пример #4
0
        public ViewResult SuggestItems()
        {
            UserIM uim = new UserIM(db);
            TableIM im = new TableIM(db);
            user authUser = Util.User.UserUtil.getAuthenticatedUser(Request);
            if (authUser == null)
            {
                return View("LogOn", "User");
            }
            user dbUser = uim.find(authUser.id);
            int t_id = (int)dbUser.current_table_id;
            restaurant r = db.tables.Find(t_id).restaurant;

            ViewBag.Suggest = "Items are suggested based on your ratings and order history.";

            return View("SuggestedItems", UserUtil.GetSuggestions(authUser, r));
        }
Пример #5
0
        public ViewResult PopularItemsByRating(menu menu)
        {
            UserIM uim = new UserIM(db);
            TableIM im = new TableIM(db);
            ReportsIM rim = new ReportsIM(db);
            MenuItemIM miIM = new MenuItemIM(db);

            user authUser = Util.User.UserUtil.getAuthenticatedUser(Request);
            if (authUser == null)
            {
                return View("LogOn", "User");
            }
            user dbUser = uim.find(authUser.id);
            int t_id = (int)dbUser.current_table_id;
            restaurant r = db.tables.Find(t_id).restaurant;

            IEnumerable<MostPopularDishViewModel> mostPopular = rim.findMostPopularCustomer(r);
            List<KeyValuePair<TouchForFood.Models.menu_item, double>> list = new List<KeyValuePair<TouchForFood.Models.menu_item, double>>();
            foreach(var dish in mostPopular){
                menu_item mi = miIM.find(dish.menuItemId);

                list.Add(new KeyValuePair<menu_item,double>(mi,ItemUtil.getAverageRating(mi)));
            }

            list.Sort((firstPair, nextPair) =>
            {
                return nextPair.Value.CompareTo(firstPair.Value);
            }
            );

            ViewBag.Suggest = "Items are ranked according to rating.";

            return View("SuggestedByRating", list);
        }
Пример #6
0
 public UserController()
 {
     im = new UserIM(db);
     om = new UserOM(db);
 }
Пример #7
0
        public ViewResult PopularItems()
        {
            UserIM uim = new UserIM(db);
            TableIM im = new TableIM(db);
            ReportsIM rim = new ReportsIM(db);
            MenuItemIM miIM = new MenuItemIM(db);

            user authUser = Util.User.UserUtil.getAuthenticatedUser(Request);
            if (authUser == null)
            {
                return View("LogOn", "User");
            }
            user dbUser = uim.find(authUser.id);
            int t_id = (int)dbUser.current_table_id;
            restaurant r = db.tables.Find(t_id).restaurant;

            IEnumerable<MostPopularDishViewModel> mostPopular = rim.findMostPopularCustomer(r);
            List<KeyValuePair<TouchForFood.Models.menu_item, int>> list = new List<KeyValuePair<TouchForFood.Models.menu_item, int>>();
            foreach(var dish in mostPopular){
                menu_item mi = miIM.find(dish.menuItemId);

                list.Add(new KeyValuePair<menu_item,int>(mi,dish.timesOrdered));
            }

            ViewBag.Suggest = "Items are ranked according to the number of times they have been ordered.";

            return View("SuggestedItems", list);
        }