public List<Hobby> getHobbiesByGroup(Group g)
 {
     var hobbies = (from c in db.HobbyGroupConnections
                   where g.ID == c.GroupID
                   join h in db.Hobbies on c.HobbyID equals h.ID
                   select h).ToList();
     return hobbies;
 }
        public bool addHobbyGroupConnection(Hobby h, Group g)
        {
            HobbyGroupConnection hConnection = new HobbyGroupConnection();
            hConnection.GroupID = g.ID;
            hConnection.HobbyID = h.ID;
            db.HobbyGroupConnections.Add(hConnection);

            return db.SaveChanges() != 0;
        }
        public ActionResult CreateGroup(FormCollection collection)
        {
            Group g = new Group();
            ApplicationUser currentUser = accountService.getUserByName(User.Identity.Name);
            List<Hobby> currentUserHobbies = hobbyService.getHobbiesByUser(currentUser);

            g.Name = collection["groupName"];
            g.Description = collection["groupDesc"];

            groupService.addGroup(g);

            foreach (Hobby h in currentUserHobbies)
            {
                if (collection[h.Name] == h.Name)
                {
                    hobbyService.addHobbyGroupConnection(h, g);
                }
            }

            groupService.addAdminToGroup(g, currentUser);

            string url = this.Request.UrlReferrer.AbsoluteUri;
            return Redirect(url);
        }
 public List<Status> getGroupStatusHistory(Group g)
 {
     var statuses = (from s in db.Statuses
                     where s.GroupID == g.ID
                     orderby s.Date descending
                     select s).ToList();
     return statuses;
 }