public Goal OutOfGoalViewModel(GoalViewModel goalViewModel, string username)
        {
            Sports sports = new Sports(SessionProvider.CurrentSession);
            Venues venues = new Venues(SessionProvider.CurrentSession);
            Goals goals = new Goals(SessionProvider.CurrentSession);
            Users users = new Users(SessionProvider.CurrentSession);

            Goal goal;
            if(goalViewModel.Id == 0)
            {
                goal = new Goal();
                goal.CreatedOn = DateTime.Now;
                goal.UserCreator = users.GetByUserName(username);
            }
            else
            {
                goal = goals.GetById(goalViewModel.Id);
            }
            
            goal.Name = goalViewModel.Name;
            goal.Date = goalViewModel.Date;
            goal.Description = goalViewModel.Description;

            goal.Web = goalViewModel.Web;
            goal.Venue = venues.GetById(Convert.ToInt32(goalViewModel.VenueId));
            goal.Sport = sports.GetById(Convert.ToInt32(goalViewModel.SportId));

            goal.Venue.Latitude = Convert.ToInt32(goalViewModel.VenueLatitude);
            goal.Venue.Longitude = Convert.ToInt32(goalViewModel.VenueLongitude);

            return goal;
        }
        public ActionResult Unsubscribe([Bind(Prefix = "id")] int goalId)
        {
            var goals = new Goals(SessionProvider.CurrentSession);

            var goal = goals.GetById(goalId);

            var goalParticipant = goal.Participants.Single(s => s.User.Username == User.Identity.Name);

            goal.Participants.Remove(goalParticipant);

            return View("MembershipWidget", new MembershipManagementViewModel(false, goalId));
        }
        public ActionResult SubscriptionStatus(int goalId)
        {
            var goals = new Goals(SessionProvider.CurrentSession);
            var users = new Users(SessionProvider.CurrentSession);

            var goal = goals.GetById(goalId);
            var user = users.GetByUserName(User.Identity.Name);

            if(goal.IsParticipant(user.Username))
            {
                return View("MembershipWidget", new MembershipManagementViewModel(true, goalId));
            }
            return View("MembershipWidget", new MembershipManagementViewModel(false, goalId));
        }
        public ActionResult Edit_(Goal viewModelGoal)
        {
            // This would be the manual process, using the update hard coded. 
            // Better use the UpdateModel integrated in the framework!
            UpdateModel(viewModelGoal);

            var goals = new Goals(SessionProvider.CurrentSession);
            var currentGoal = goals.GetById(viewModelGoal.Id);

            currentGoal.Description = viewModelGoal.Description;
            currentGoal.Name = viewModelGoal.Name;
            currentGoal.Web = viewModelGoal.Web;

            goals.Update(currentGoal);

            return RedirectToAction("Details", new { Id = currentGoal.Id });
        }
        public ActionResult Subscribe([Bind(Prefix = "id")] int goalId)
        {
            var goals = new Goals(SessionProvider.CurrentSession);

            var goal = goals.GetById(goalId);

            var users = new Users(SessionProvider.CurrentSession);

            var user = users.GetByUserName(User.Identity.Name);

            goal.Participants.Add(new GoalParticipant()
                                      {
                                          Goal = goal,
                                          User = user,
                                          SignedOnDate = DateTime.Now
                                      });

            return View("MembershipWidget", new MembershipManagementViewModel(true, goalId));
        }