Esempio n. 1
0
 public HttpResponseMessage Post(Location location)
 {
     if (base.ModelState.IsValid)
     {
         _locationsRepo.AddLocation(location);
         return new HttpResponseMessage(HttpStatusCode.OK);
     }
     return base.Request.CreateErrorResponse(HttpStatusCode.BadRequest, base.ModelState);
 }
 public Location AddLocation(Location location)
 {
     using (SqlConnection connection = new SqlConnection(Settings.GetConnectionString()))
     {
         DynamicParameters param = new DynamicParameters();
         param.Add("@City", location.City);
         param.Add("@Country", location.Country);
         param.Add("@LocationID", dbType: DbType.Int32, direction: ParameterDirection.Output);
         connection.Execute("LocationsAdd", param, commandType: CommandType.StoredProcedure);
         location.LocationID = param.Get<int>("@LocationID");
     }
     return location;
 }
Esempio n. 3
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));
        }
Esempio n. 4
0
 public MockRepository()
 {
     Site site = new Site
     {
         SiteName = "Test",
         SiteLogoURL = "TestUrl"
     };
     mockSite = site;
     BootcampLocation location = new BootcampLocation
     {
         BootcampID = 2,
         LocationID = 1
     };
     MockBootcampLocation = location;
     Location location2 = new Location
     {
         LocationID = 1,
         City = "Houston",
         Country = "USA"
     };
     mockLocation = location2;
     Technology technology = new Technology
     {
         Name = "Javascript"
     };
     mockTechnology = technology;
     BootcampTechnology technology2 = new BootcampTechnology
     {
         BootcampID = 1,
         TechnologyID = 1
     };
     mockBootcampTechnology = technology2;
     ContactForm form = new ContactForm
     {
         ContactFormID = 1,
         Email = "*****@*****.**",
         Message = "hello there",
         Name = "Charles"
     };
     MockContactForm = form;
     Bootcamp bootcamp = new Bootcamp
     {
         BootcampID = 1,
         PrimaryTechnologyID = 1,
         Name = "App Academy",
         LocationID = 2,
         Price = 0x2ee0,
         LengthInWeeks = 10,
         Website = "http://www.appacademy.com",
         LogoLink = "http://sample.com"
     };
     mockBootcamp = bootcamp;
     BootcampSession session = new BootcampSession
     {
         BootcampSessionID = 3,
         BootcampID = 1,
         LocationID = 1,
         TechnologyID = 1,
         StartDate = new DateTime(0x7de, 8, 1),
         EndDate = new DateTime(0x7de, 10, 0x16)
     };
     mockBootcampSession = session;
     Link link = new Link
     {
         LinkID = 1,
         URL = "http://www.wsj.com",
         LinkText = "Bootcamps in the WSJ",
         SiteID = 1,
         Date = new DateTime(0x7de, 2, 0x16),
         BootcampID = 1
     };
     mockLink = link;
     Review review = new Review
     {
         ReviewID = 1,
         ReviewText = "It was good",
         IsVerified = false,
         BootcampID = 2,
         UserID = 1
     };
     mockReview = review;
     User user = new User
     {
         UserID = 1,
         Email = "*****@*****.**",
         Password = "******"
     };
     mockUser = user;
 }