//
        public BootcampSessionAddAng Get(int id)
        {
            //create a new view model, passing in the desired
            //session id and name
            BootcampSessionAddAng ang = new BootcampSessionAddAng
            {
                BootcampSessionId = id
            };

            ang.BootcampName = _bootcampRepo.GetBootcampByID(id).Name;

            //add all of the bootcamp's locations to the view model
            foreach (BootcampLocation location in _bootcampLocationsRepo.GetAllBootcampLocationsByBootcampId(id))
            {
                Location    locationById = _locationRepo.GetLocationById(location.LocationID);
                LocationAng item         = new LocationAng
                {
                    LocationId = location.LocationID,
                    Name       = locationById.City + ", " + locationById.Country
                };
                ang.Locations.Add(item);
            }

            //add all of the bootcamp's technologies to the view model
            foreach (BootcampTechnology technology in _bootcampTechRepo.GetAllBootcampTechnologiesByBootcampId(id))
            {
                TechnologyAng ang3 = new TechnologyAng
                {
                    TechnologyId = technology.TechnologyID.Value,
                    Name         = _techRepo.GetTechnologyById(technology.TechnologyID.Value).Name
                };
                ang.Technologies.Add(ang3);
            }
            return(ang);
        }
Exemplo n.º 2
0
 public HttpResponseMessage Post(BootcampTechnology bootcampTechnology)
 {
     if (!_bootcampTechRepo.GetAllBootcampTechnologiesByBootcampId(bootcampTechnology.BootcampID.Value).Any <BootcampTechnology>(m => ((m.TechnologyID == bootcampTechnology.TechnologyID) && ModelState.IsValid)))
     {
         _bootcampTechRepo.AddBootcampTechnology(bootcampTechnology);
         return(new HttpResponseMessage(HttpStatusCode.OK));
     }
     return(base.Request.CreateErrorResponse(HttpStatusCode.BadRequest, base.ModelState));
 }
Exemplo n.º 3
0
        //filters bootcamps when user searches on home page
        public List<Bootcamp> FilterBootcamps(SearchParams searchParams)
        {
            //get all the bootcamps
            var allBootcamps = _bootcampRepo.GetAllBootcamps();

            //create empty list of bootcamps to which the ones which 
            //pass the filter test will be added
            var filteredBootcamps = new List<Bootcamp>();

            //get the price range based on user selection
            PriceRange priceRange = new PriceRange();
            if (searchParams.SelectedPriceRange.HasValue)
            {
                priceRange = GetPriceRange(searchParams.SelectedPriceRange.Value);
            }

            //loop through each bootcamp and check each user selection against it
            foreach (FutureCodr.Models.Bootcamp bootcamp in allBootcamps)
            {
                //first get all of the bootcamp's location and technology IDs
                //to compare to the user's selection
                List<int> bootcampLocationIds = _bootcampLocationsRepo
                                                .GetAllBootcampLocationsByBootcampId(bootcamp.BootcampID)
                                                .Select(m => m.LocationID).ToList();
                List<int> bootcampTechnologyIds = _bootcampTechnologyRepo
                                                .GetAllBootcampTechnologiesByBootcampId(bootcamp.BootcampID)
                                                .Select(m => m.TechnologyID).ToList();

                //then check each bootcamp against price, location and technology
                if ((!searchParams.SelectedPriceRange.HasValue || ((bootcamp.Price >= priceRange.Min) && (bootcamp.Price <= priceRange.Max)))
                 && (!searchParams.SelectedLocationId.HasValue || !bootcampLocationIds.Contains(searchParams.SelectedLocationId))
                 && (!searchParams.SelectedTechnologyId.HasValue || !bootcampTechnologyIds.Contains(searchParams.SelectedTechnologyId))
                {
                    filteredBootcamps.Add(bootcamp);
                }
            }

            //convert all of the bootcamps that passed the filter into the
            //correct format and return the list
            var filteredAndConvertedBootcampList = new List<FutureCodr.UI.Models.Home.Bootcamp>();
            foreach (FutureCodr.Models.Bootcamp bootcamp in list2)
            {
                filteredAndConvertedBootcampList.Add(ConvertBootcampFormat(bootcamp));
            }
            return filteredAndConvertedBootcampList;
        }
Exemplo n.º 4
0
        public ActionResult Index(string id)
        {
            //parse URL to get bootcamp ID
            string bootcampName = id.Replace("-", " ");
            int?   bootcampID   = _bootcampRepo.GetBootcampIDByName(bootcampName);

            //if bootcamp does not exist, redirect to the home page
            if (id == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            //get bootcampID and locationID
            var bootcampByID = _bootcampRepo.GetBootcampByID((int)bootcampID);
            var locationById = _locationRepo.GetLocationById(bootcampByID.LocationID);

            //insert basic bootcamp info into view model
            var model = new BootcampViewModel
            {
                BootcampID = (int)bootcampID,
                Location   = locationById.City + ", " + locationById.Country,
                Name       = bootcampByID.Name,
                LogoLink   = bootcampByID.LogoLink,
                Url        = bootcampByID.Website,
                Price      = Helper.GetPriceString(bootcampByID.Price, _locationRepo.GetLocationById(bootcampByID.LocationID).Country)
            };


            //get all links info for bootcamp and add to view model
            foreach (var link in _linkRepo.GetAllLinksByBootcampId((int)bootcampID))
            {
                Site   siteById = _siteRepo.GetSiteById((int)link.SiteID);
                string linkText = link.LinkText;
                if (linkText.Length > 60)
                {
                    linkText = linkText.Substring(0, 60) + "...";
                }
                FutureCodr.UI.Models.Bootcamp.Link item = new FutureCodr.UI.Models.Bootcamp.Link
                {
                    URL         = link.URL,
                    SiteName    = siteById.SiteName,
                    SiteLogoURL = siteById.SiteLogoURL,
                    Title       = linkText,
                    Date        = link.Date
                };
                model.Links.Add(item);
            }

            //order links by most recent
            model.Links = (from m in model.Links
                           orderby m.Date descending
                           select m).ToList();

            //add bootcamp locations to view model
            foreach (var location2 in _bootcampLocationsRepo.GetAllBootcampLocationsByBootcampId((int)bootcampID))
            {
                FutureCodr.Models.Location             location3 = _locationRepo.GetLocationById(location2.LocationID);
                FutureCodr.UI.Models.Bootcamp.Location location4 = new FutureCodr.UI.Models.Bootcamp.Location
                {
                    City = location3.City,
                    Name = location3.City + ", " + location3.Country,
                    Id   = location2.LocationID
                };
                model.Locations.Add(location4);
            }

            //add bootcamp sessions to view model if they start in the future
            foreach (var session in _sessionRepo.GetBootcampSessionsByBootcampId((int)bootcampID))
            {
                if (session.StartDate > DateTime.Now)
                {
                    Session session2 = new Session
                    {
                        Technology = _technologyRepo.GetTechnologyById(session.TechnologyID.Value).Name,
                        Location   = _locationRepo.GetLocationById((int)session.LocationID).City +
                                     ", " +
                                     _locationRepo.GetLocationById(session.LocationID.Value).Country,
                        StartDate = session.StartDate,
                        EndDate   = session.EndDate
                    };
                    model.Sessions.Add(session2);
                }
            }

            //order sessions by soonest to start
            model.Sessions = (from m in model.Sessions
                              orderby m.StartDate
                              select m).ToList();

            //add bootcamp technologies to the view model
            foreach (var technology in _bootcampTechnologyRepo.GetAllBootcampTechnologiesByBootcampId((int)bootcampID))
            {
                FutureCodr.UI.Models.Bootcamp.Technology technology2 = new FutureCodr.UI.Models.Bootcamp.Technology
                {
                    Name = _technologyRepo.GetTechnologyById(technology.TechnologyID.Value).Name,
                    Id   = technology.TechnologyID.Value
                };
                model.Technologies.Add(technology2);
            }

            //return the strongly typed view with the view model passed in
            return(View(model));
        }
Exemplo n.º 5
0
 public void GetAllBootcampTechnologiesByBootcampIdTest()
 {
     Assert.AreEqual(repo.GetAllBootcampTechnologiesByBootcampId(1).Count, 1);
 }