public List <ListingInfo> GetListings()
        {
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                var listingModels           = db.ListingModels.ToList();
                List <ListingInfo> listings = new List <ListingInfo>();

                foreach (ListingModel listing in listingModels)
                {
                    var l = new ListingInfo();
                    l.Id           = listing.Id;
                    l.UrlId        = listing.UrlId;
                    l.Title        = listing.Title;
                    l.StartDate    = listing.StartDate;
                    l.EndDate      = listing.EndDate;
                    l.Area         = listing.Area;
                    l.AgeGroup     = listing.AgeGroup;
                    l.Frequency    = listing.Frequency;
                    l.Description  = listing.Description;
                    l.HangoutUrl   = listing.HangoutUrl;
                    l.HangoutStart = listing.HangoutStart;
                    l.TeacherId    = listing.TeacherId;
                    l.Open         = listing.Open;
                    l.Teacher      = l.GetTeacherUserName(listing);

                    listings.Add(l);
                }

                CheckForExpiredListings(listings);
                CheckForExpiredHangouts(listings);

                return(listings);
            }
        }
        public List <ListingInfo> GetListingsByCurrentUser(string userName)
        {
            var currentUserName         = userName;
            List <ListingInfo> listings = new List <ListingInfo>();
            var userInDatabase          = false;

            //Check if the current user is in the database
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                userInDatabase = db.iMentorUsers.Where(x => x.UserName.Equals(currentUserName)).FirstOrDefault() != null;
            }

            if (userInDatabase)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    //Get the current user from the database
                    var iMentorUser = db.iMentorUsers.Where(x => x.UserName.Equals(currentUserName)).FirstOrDefault();

                    //Get current users assigned listings
                    var assignments = db.AssignedListings.Where(x => x.UserId == iMentorUser.Id);

                    //Get listings base on the assignments
                    var assidnedListings = new List <ListingModel>();
                    foreach (AssignedListing assignment in assignments)
                    {
                        assidnedListings.Add(db.ListingModels.Where(x => x.Id == assignment.ListingId).FirstOrDefault());
                    }



                    foreach (ListingModel listing in assidnedListings)
                    {
                        var l = new ListingInfo();
                        l.Id           = listing.Id;
                        l.UrlId        = listing.UrlId;
                        l.Title        = listing.Title;
                        l.StartDate    = listing.StartDate;
                        l.EndDate      = listing.EndDate;
                        l.Area         = listing.Area;
                        l.AgeGroup     = listing.AgeGroup;
                        l.Frequency    = listing.Frequency;
                        l.Description  = listing.Description;
                        l.HangoutUrl   = listing.HangoutUrl;
                        l.HangoutStart = listing.HangoutStart;
                        l.TeacherId    = listing.TeacherId;
                        l.Open         = listing.Open;
                        l.Teacher      = l.GetTeacherUserName(listing);

                        listings.Add(l);
                    }

                    CheckForExpiredListings(listings);
                }
            }

            return(listings);
        }