Example #1
0
        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;
            }
        }
Example #2
0
        public string UpdateListing(ListingInfo listing)
        {
            if (listing != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    int no = Convert.ToInt32(listing.Id);
                    var l = db.ListingModels.Where(x => x.Id == no).FirstOrDefault();

                    if (l != null)
                    {
                        l.Title = listing.Title;
                        l.UrlId = listing.UrlId;
                        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;
                        db.SaveChanges();
                        return "Listing Updated";
                    }
                    else
                    {
                        return "Invalid Listing";
                    }
                }
            }
            else
            {
                return "Invalid Listing";
            }
        }
        public void UpdateListingTest()
        {
            ManageController controller = new ManageController();
            ListingModel listingModel = controller.ReturnLastAddedListing();
            ListingInfo listing = new ListingInfo();

            listing.Id          = listingModel.Id;
            listing.Title       = "Unit Test (Updated)";
            listing.StartDate   = listingModel.StartDate;
            listing.EndDate     = listingModel.EndDate;
            listing.Area        = listingModel.Area;
            listing.Frequency   = listingModel.Frequency;
            listing.Description = "Unit testing... again!";
            listing.HangoutUrl  = listingModel.HangoutUrl;
            listing.TeacherId   = listingModel.TeacherId;
            listing.Open        = listingModel.Open;
            listing.Teacher     = "*****@*****.**";

            //Check that the UpdateListing function completed successfully
            Assert.AreEqual(controller.UpdateListing(listing), "Listing Updated");

            //Check that the listing was actually updated in the database
            ListingModel lastAdded = controller.ReturnLastAddedListing();

            Assert.IsTrue( listing.Title        == lastAdded.Title          &&
                           listing.StartDate    == lastAdded.StartDate      &&
                           listing.EndDate      == lastAdded.EndDate        &&
                           listing.Area         == lastAdded.Area           &&
                           listing.Frequency    == lastAdded.Frequency      &&
                           listing.Description  == lastAdded.Description    &&
                           listing.HangoutUrl   == lastAdded.HangoutUrl     &&
                           listing.TeacherId    == lastAdded.TeacherId      &&
                           listing.Open         == lastAdded.Open);
        }
Example #4
0
        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;
        }
Example #5
0
 public string UpdateListing(ListingInfo listing)
 {
     return listingService.UpdateListing(listing);
 }