public ActionResult ShowRoommatePage()
        {
            //show the home page of roommates
            if (!Authorize())
            {
                return(RedirectToAction("RedirectByUser", "Home"));
            }
            //remove gid from the session (added at showExpenses action)
            Session.Remove("gid");
            //get the groups of the user from DB
            User             u    = (User)(Session["CurrentUser"]);
            GroupRoommateDal gdal = new GroupRoommateDal();
            List <int>       gids = (from g in gdal.GroupsRoommates
                                     where g.userName == u.UserName
                                     select g.groupID).ToList <int>();
            GroupDal     groupd   = new GroupDal();
            List <Group> MyGroups = (from g in groupd.Groups
                                     where gids.Contains(g.gid)
                                     select g).ToList <Group>();
            VMGroups grp = new VMGroups()
            {
                Groups = MyGroups
            };

            return(View(grp));
        }
        public ActionResult AddGroup()
        {
            //add new roommate groupaction

            if (!Authorize())
            {
                return(RedirectToAction("RedirectByUser", "Home"));
            }
            GroupDal grpDal   = new GroupDal();
            VMGroups groupsVM = new VMGroups
            {
                Group  = new Group(),
                Groups = grpDal.Groups.ToList <Group>()
            };

            return(View(groupsVM));
        }
        public ActionResult AddGroupSubmit([ModelBinder(typeof(GroupBinder))] Group grp)
        {
            //add the new group to DB

            if (!Authorize())
            {
                return(RedirectToAction("RedirectByUser", "Home"));
            }
            VMGroups groupsVM = new VMGroups();
            GroupDal grpDal   = new GroupDal();

            ModelState.Clear();
            TryValidateModel(grp);
            if (ModelState.IsValid)
            {
                grp.managerUserName = ((User)(Session["CurrentUser"])).UserName;
                grpDal.Groups.Add(grp);
                try
                {
                    grpDal.SaveChanges();
                    //reset a new group object to view
                    groupsVM.Group = new Group();
                    GroupRoommate grpRmt = new GroupRoommate()
                    {
                        groupID  = grp.gid,
                        userName = grp.managerUserName
                    };
                    GroupRoommateDal grpRmtDal = new GroupRoommateDal();
                    grpRmtDal.GroupsRoommates.Add(grpRmt);
                    grpRmtDal.SaveChanges();
                    ViewBag.addGroupSuccess = "הקבוצה התווספה בהצלחה!";
                }
                catch (DbUpdateException)
                {
                    ViewBag.addNewGroupError = "התרחשה שגיאה בהוספת הקבוצה";
                    groupsVM.Group           = grp;
                }
            }
            else
            {
                groupsVM.Group = grp;
            }
            groupsVM.Groups = grpDal.Groups.ToList <Group>();
            return(View("AddGroup", groupsVM));
        }
        public ActionResult AddUserToGroup()
        {
            //add registered users to roommate groups of the current manager
            if (!Authorize())
            {
                return(RedirectToAction("RedirectByUser", "Home"));
            }
            User     u      = (User)(Session["CurrentUser"]);
            GroupDal groupd = new GroupDal();
            //get only the groups of the manager
            List <Group> MyGroups = (from g in groupd.Groups
                                     where g.managerUserName == u.UserName
                                     select g).ToList <Group>();
            VMGroups grp = new VMGroups()
            {
                Groups = MyGroups
            };

            return(View(grp));
        }