// GET: TourDtoes/Create
        public async Task <ActionResult> Create(int?tourId)
        {
            bool tour_Selected = tourId.HasValue;

            ViewBag.TourSelected = tour_Selected;
            var request = new HTTPrequest();


            List <TourSimpleDto>  toursList    = new List <TourSimpleDto>();
            TourSimpleDto         tour         = new TourSimpleDto();
            List <SelectListItem> tourDropdown = new List <SelectListItem>();

            // Checks if page was access from Index of all MediaFiles, or Direct from a particular artefact
            if (tour_Selected == true)
            {
                tour = await request.Get <TourSimpleDto>("api/tour/" + tourId);

                if (tour == null)
                {
                    return(HttpNotFound());
                }
                else
                {
                    tourDropdown.Add(new SelectListItem()
                    {
                        Text  = tour.Id + ": " + tour.Name,
                        Value = tour.Id.ToString()
                    });
                    ViewBag.TourName = tour.Name;
                    ViewBag.TourID   = tour.Id.ToString();
                }
            }
            else
            {
                toursList = await request.Get <List <TourSimpleDto> >("api/tour?pageNumber=0&numPerPage=5-0&isDeleted=false");

                if (toursList != null && toursList.Any())
                {
                    foreach (var tours in toursList)
                    {
                        tourDropdown.Add(new SelectListItem()
                        {
                            Text  = tours.Id + ": " + tours.Name,
                            Value = tours.Id.ToString()
                        });
                    }
                }
            }

            ViewBag.TourList = tourDropdown;
            //ARTEFACT DROPDOWN
            List <SelectListItem> artefactDropdown = new List <SelectListItem>();

            artefactDropdown = await PopulateArtefactDropdown();

            ViewBag.ArtefactList = artefactDropdown;
            return(View());
        }
        public async Task <ActionResult> Create(TourArtefactDto tourArtefact, int?tourId)
        {
            // Checks Order is not Negative or Empty
            if (tourArtefact.Order < 0 || tourArtefact.Order == null)
            {
                ViewBag.OrderValidation = "Order must be a positive integer.";
                return(View(tourArtefact));
            }
            bool tour_Selected = tourId.HasValue;
            //TOUR CATEGORY
            List <SelectListItem> tourDropdown = new List <SelectListItem>();

            if (tour_Selected)
            {
                tourDropdown = await PopulateTourDropdown(tour_Selected, tourId);
            }
            else
            {
                tourDropdown = await PopulateTourDropdown(tour_Selected, null);
            }
            ViewBag.TourList = tourDropdown;
            //ARTEFACT DROPDOWN
            List <SelectListItem> artefactDropdown = new List <SelectListItem>();

            artefactDropdown = await PopulateArtefactDropdown();

            ViewBag.ArtefactList = artefactDropdown;

            ViewBag.TourID = tourId.ToString();

            var     tourRequest = new HTTPrequest();
            TourDto tourCheck   = await tourRequest.Get <TourDto>("api/tour/" + tourArtefact.Tour.Id);

            TourArtefactDto newTourArtefact = new TourArtefactDto();

            if (tourCheck.Artefacts.Any(m => m.Order == tourArtefact.Order) && tourCheck.Artefacts.Any(m => m.Id == tourArtefact.Artefact.Id))
            {
                ViewBag.IndexAvail = false;
                return(View(newTourArtefact));
            }

            newTourArtefact.Artefact = await tourRequest.Get <ArtefactSimpleDto>("api/artefact/" + tourArtefact.Artefact.Id);

            TourSimpleDto tour = await tourRequest.Get <TourSimpleDto>("api/tour/" + tourArtefact.Tour.Id);

            newTourArtefact.Tour         = tour;
            newTourArtefact.Order        = tourArtefact.Order;
            newTourArtefact.CreatedDate  = DateTime.Now;
            newTourArtefact.ModifiedDate = DateTime.Now;
            var request = new HTTPrequest();
            await request.Post <TourArtefactDto>("api/tourArtefact", newTourArtefact);

            return(RedirectToAction("Index", "ToursArtefacts", new { tId = newTourArtefact.Tour.Id, recentAction = "Created", recentNameT = newTourArtefact.Tour.Name, recentIdT = newTourArtefact.Tour.Id, recentNameA = newTourArtefact.Artefact.Name, recentIdA = newTourArtefact.Artefact.Id }));
        }
        TourArtefactDto CreateTestTourArtefact()
        {
            TourSimpleDto newTour = new TourSimpleDto {
                Id = CreateTestTour().Id, Name = CreateTestTour().Name
            };
            ArtefactSimpleDto newArtefact = new ArtefactSimpleDto {
                Id = CreateTestArtefact().Id, Name = CreateTestArtefact().Name
            };


            TourArtefactDto tourArtefact = new TourArtefactDto()
            {
                Id       = 1,
                Tour     = newTour,
                Artefact = newArtefact,
                Order    = 5
            };

            tourArtefact = _controller.Create(tourArtefact);

            return(tourArtefact);
        }
        public async Task <List <SelectListItem> > PopulateTourDropdown(bool tourSelected, int?tourId)
        {
            var request = new HTTPrequest();
            List <TourSimpleDto> toursList = await request.Get <List <TourSimpleDto> >("api/tour?pageNumber=0&numPerPage=5-0&isDeleted=false");

            List <SelectListItem> tourDropdown = new List <SelectListItem>();
            TourSimpleDto         tour         = new TourSimpleDto();

            if (tourSelected == true)
            {
                tour = await request.Get <TourSimpleDto>("api/tour/" + tourId);

                if (tour != null)
                {
                    tourDropdown.Add(new SelectListItem()
                    {
                        Text  = tour.Id + ":" + tour.Name,
                        Value = tour.Id.ToString()
                    });
                    ViewBag.TourName = tour.Name;
                    ViewBag.TourID   = tour.Id.ToString();
                }
            }
            else
            {
                foreach (var t in toursList)
                {
                    tourDropdown.Add(new SelectListItem()
                    {
                        Text  = t.Id + ": " + t.Name,
                        Value = t.Id.ToString()
                    });
                }
            }
            return(tourDropdown);
        }