public async Task <IActionResult> Upsert(TrailsViewModel obj)
        {
            if (ModelState.IsValid)
            {
                if (obj.Trail.Id == 0)
                {
                    //FLOW: Create
                    await _trailRepo.CreateAsync(Static.TrailAPIPath, obj.Trail, HttpContext.Session.GetString("JWToken"));
                }
                else
                {
                    await _trailRepo.UpdateAsync(Static.TrailAPIPath + obj.Trail.Id, obj.Trail, HttpContext.Session.GetString("JWToken"));
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                IEnumerable <NationalPark> npList = await _npRepo.GetAllAsync(Static.NationalParkAPIPath, HttpContext.Session.GetString("JWToken"));

                TrailsViewModel objVM = new TrailsViewModel()
                {
                    NationalParkList = npList.Select(i => new SelectListItem
                    {
                        Text  = i.Name,
                        Value = i.Id.ToString()
                    }),
                    //FLOW: We have to initialize trail() to prevent errors
                    Trail = obj.Trail
                };
                return(View(objVM));
            }
        }
Example #2
0
        public async Task <IActionResult> Upsert(TrailVM trailVM)
        {
            if (ModelState.IsValid)
            {
                if (trailVM.Trail.Id == 0)
                {
                    await trailRepository.CreateAsync(SD.TrainAPIUrl, trailVM.Trail, HttpContext.Session.GetString("JWTToken"));
                }
                else
                {
                    await trailRepository.UpdateAsync(SD.TrainAPIUrl + trailVM.Trail.Id, trailVM.Trail, HttpContext.Session.GetString("JWTToken"));
                }
                return(RedirectToAction(nameof(Index)));
            }

            IEnumerable <NationalPark> nationalParkList = await nationalParkRepository.GetAllAsync(SD.NationalParkAPIUrl, HttpContext.Session.GetString("JWTToken"));

            TrailVM newtrail = new TrailVM
            {
                NationalParkList = nationalParkList.Select(s => new SelectListItem()
                {
                    Text  = s.Name,
                    Value = s.Id.ToString()
                }),
                Trail = trailVM.Trail
            };

            return(View(newtrail));
        }
Example #3
0
        public async Task <IActionResult> Upsert(TrailsVM obj)
        {
            var token = HttpContext.Session.GetString("JWTToken");

            if (ModelState.IsValid)
            {
                if (obj.Trails.Id == 0)
                {
                    await _trailRepo.CreateAsync(SD.TrailAPIPath, obj.Trails, token);
                }
                else
                {
                    await _trailRepo.UpdateAsync(SD.TrailAPIPath + obj.Trails.Id.ToString(), obj.Trails, token);
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                IEnumerable <NationalPark> npList = await _npRepo.GetAllAsync(SD.NationalParkAPIPath);

                TrailsVM objVM = new TrailsVM()
                {
                    NationalParkList = npList.Select(x => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem
                    {
                        Text  = x.Name,
                        Value = x.Id.ToString()
                    }),
                    Trails = obj.Trails
                };

                return(View(objVM));
            }
        }
Example #4
0
        public async Task <IActionResult> Upsert(TrailsVm trailsVm)
        {
            if (!ModelState.IsValid)
            {
                var npList = await _npRepo.GetAllAsync(StaticDetails.NationalParksApiPath);

                var objVm = new TrailsVm
                {
                    NationalParkList = npList.Select(i => new SelectListItem
                    {
                        Text  = i.Name,
                        Value = i.Id.ToString()
                    }),
                    Trail = trailsVm.Trail
                };
                return(View(objVm));
            }

            if (trailsVm.Trail.Id == 0)
            {
                await _trailRepo.CreateAsync(StaticDetails.TrailsApiPath, trailsVm.Trail);
            }
            else
            {
                await _trailRepo.UpdateAsync(StaticDetails.TrailsApiPath, trailsVm.Trail);
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Upsert(TrailsVM obj)
        {
            if (ModelState.IsValid)
            {
                if (obj.Trails.Id == 0)
                {
                    await _trailRepo.CreateAsync(SD.TrailAPIPath, obj.Trails, HttpContext.Session.GetString("JWToken"));
                }
                else
                {
                    await _trailRepo.UpdateAsync($"{SD.TrailAPIPath}{obj.Trails.Id}", obj.Trails, HttpContext.Session.GetString("JWToken"));
                }

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                IEnumerable <NationalPark> npList = await _npRepo.GetAllAsync(SD.NationalParkAPIPath, HttpContext.Session.GetString("JWToken"));

                TrailsVM objVm = new TrailsVM()
                {
                    NationalParkList = npList.Select(i => new SelectListItem
                    {
                        Text  = i.Name,
                        Value = i.Id.ToString()
                    }),
                    Trails = obj.Trails
                };
                return(View(objVm));
            }
        }
Example #6
0
        public async Task <IActionResult> Upsert([Bind("Id", "Name", "State", "Picture", "Established")] VmTrail vmTrail)
        {
            var listNationalPark = await _npRepo.GetAllAsync(SD.NationalParkAPIPath);

            VmTrail vmTrail2 = new VmTrail
            {
                NationalParkList = listNationalPark.Select(x => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem {
                    Text = x.Name, Value = x.Id.ToString()
                })
            };

            if (!ModelState.IsValid)
            {
                return(View(vmTrail2));
            }

            if (vmTrail.Trail.Id == 0)
            {
                if (await _tRepo.CreateAsync(SD.TrailAPIPath, vmTrail.Trail))
                {
                    return(RedirectToAction("Index"));
                }
                vmTrail2.Trail = vmTrail.Trail;
                return(View(vmTrail2));
            }

            if (await _tRepo.UpdateAsync(SD.TrailAPIPath + vmTrail.Trail.Id, vmTrail.Trail))
            {
                return(RedirectToAction("Index"));
            }

            vmTrail2.Trail = vmTrail.Trail;
            return(View(vmTrail2));
        }
Example #7
0
        public async Task <IActionResult> Upsert(TrailViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                var nationalParks = await _nationalParkRepository.GetAll(AppConstants.NationalParkApiPath);

                viewModel.NationalParks = nationalParks.Select(p => new SelectListItem()
                {
                    Text  = p.Name,
                    Value = p.Id.ToString()
                });

                return(View(viewModel));
            }

            if (viewModel.Trail.Id == 0)
            {
                await _trailRepository.CreateAsync(AppConstants.TrailsApiPath, viewModel.Trail);
            }
            else
            {
                await _trailRepository.UpdateAsync(AppConstants.TrailsApiPath, viewModel.Trail.Id, viewModel.Trail);
            }

            return(RedirectToAction(nameof(Index)));
        }
Example #8
0
        public async Task <IActionResult> Upsert(TrailsVM obj)
        {
            if (ModelState.IsValid)
            {
                if (obj.Trail.Id == 0)
                {
                    //Create
                    await _trailRepo.CreateAsync(SD.TrailAPIPath, obj.Trail, HttpContext.Session.GetString("JWToken"));
                }
                else
                {
                    await _trailRepo.UpdateAsync(SD.TrailAPIPath + obj.Trail.Id, obj.Trail, HttpContext.Session.GetString("JWToken"));
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                //Populate Dropdown with National Parks
                IEnumerable <NationalPark> npList = (IEnumerable <NationalPark>) await _npRepo.GetAllAsync(SD.NationalParkAPIPath, HttpContext.Session.GetString("JWToken"));

                //Populating Trails View Model with National Park list for dropdown
                TrailsVM objVM = new TrailsVM()
                {
                    NationalParkList = npList.Select(i => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem
                    {
                        Text  = i.Name,
                        Value = i.Id.ToString()
                    }),
                    //Have to instantiate trails when accessing it from VM
                    Trail = obj.Trail
                };
                //Return back to he view with object
                return(View(objVM));
            }
        }
Example #9
0
        public async Task <IActionResult> Upsert(TrailsVM obj)
        {
            if (ModelState.IsValid)
            {
                if (obj.Trail.Id == 0)
                {
                    await _trailRepo.CreateAsync(SD.TrailAPIPath, obj.Trail);
                }
                else
                {
                    await _trailRepo.UpdateAsync(SD.TrailAPIPath + obj.Trail.Id, obj.Trail);
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                IEnumerable <NationalPark> npList = await _npRepo.GetAllAsync(SD.NationalParkAPIPath);

                TrailsVM objVM = new TrailsVM()
                {
                    NationalParkList = npList.Select(i => new SelectListItem
                    {
                        Text  = i.Name,
                        Value = i.Id.ToString()
                    }),
                    Trail = obj.Trail
                };
                return(View(objVM));
            }
        }
Example #10
0
        public async Task <IActionResult> Upsert(TrailsVM obj)
        {
            if (ModelState.IsValid)
            {
                if (obj.Trail.Id == 0)
                {
                    await trailRepository.CreateAsync(SD.TrailApiPath, obj.Trail);
                }
                else
                {
                    await trailRepository.UpdateAsync(SD.TrailApiPath + obj.Trail.Id, obj.Trail);
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                IEnumerable <NationalPark> npList = await nationalParkRepository.GetAllAsync(SD.NationalParkApiPath);

                TrailsVM objVM = new TrailsVM()
                {
                    NationalParkList = npList.Select(x => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem
                    {
                        Value = x.Id.ToString(),
                        Text  = x.Name
                    }),
                    Trail = obj.Trail
                };
                return(View(objVM));
            }
        }
Example #11
0
        public async Task <IActionResult> Upsert(TrailViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Trail.Id == 0)
                {
                    await _trailRepository.CreateAsync(StaticDetails.TrailsApiUrl, model.Trail);
                }
                else
                {
                    await _trailRepository.UpdateAsync(StaticDetails.TrailsApiUrl + model.Trail.Id, model.Trail);
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                var nationalParksList = await _nationalPark.GetAllAsync(StaticDetails.NationalParkApiUrl);

                TrailViewModel trailViewModel = new TrailViewModel()
                {
                    NationalParks = nationalParksList.Select(i => new SelectListItem
                    {
                        Text  = i.Name,
                        Value = i.Id.ToString()
                    }),
                    Trail = model.Trail
                };
                return(View(trailViewModel));
            }
        }
Example #12
0
        public async Task <IActionResult> Upsert(TrailVM obj)
        {
            if (ModelState.IsValid)
            {
                if (obj.Trail.Id == 0)
                {
                    await _trailRepository.CreateAsync(SD.TrailAPIPath, obj.Trail, HttpContext.Session.GetString("JWToken"));
                }
                else
                {
                    await _trailRepository.UpdateAsync(SD.TrailAPIPath + obj.Trail.Id, obj.Trail, HttpContext.Session.GetString("JWToken"));
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                // create object list nationalpark
                IEnumerable <NationalPark> npList = await _nationalParkRepository.GetAllAsync(SD.NationalParkAPIPath, HttpContext.Session.GetString("JWToken"));

                TrailVM objVM = new TrailVM()
                {
                    NationalParkList = npList.Select(i => new SelectListItem
                    {
                        Text  = i.Name,
                        Value = i.Id.ToString()
                    }),
                    Trail = obj.Trail
                };
                return(View(objVM));
            }
        }
        public async Task <IActionResult> Upsert(TrailsVM trailVM)
        {
            if (ModelState.IsValid)
            {
                if (trailVM.Trail.Id == 0)
                {
                    await _trailRepository.CreateAsync(SD.TrailAPIPath, trailVM.Trail, Token);
                }
                else
                {
                    await _trailRepository.UpdateAsync(SD.TrailAPIPath + trailVM.Trail.Id, trailVM.Trail, Token);
                }

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                IEnumerable <NationalPark> nationalParks = await _npRepository.GetAllAsync(SD.NationalParkAPIPath, Token);

                TrailsVM objToReturn = new TrailsVM()
                {
                    NationalParks = nationalParks.Select(x => new SelectListItem()
                    {
                        Text  = x.Name,
                        Value = x.Id.ToString()
                    }),
                    Trail = trailVM.Trail
                };
                return(View(objToReturn));
            }
        }
Example #14
0
        public async Task <IActionResult> Upsert(TrailsVM obj)
        {
            if (ModelState.IsValid)
            {
                if (obj.Trail.Id == 0)
                {
                    await _tRepo.CreateAsync(StaticDetails.TrailAPIPath, obj.Trail, HttpContext.Session.GetString("JWToken"));
                }
                else
                {
                    await _tRepo.UpdateAsync(StaticDetails.TrailAPIPath + obj.Trail.Id, obj.Trail, HttpContext.Session.GetString("JWToken"));
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                IEnumerable <CampingPark> cpList = await _cpRepo.GetAllAsync(StaticDetails.CampingParkAPIPath, HttpContext.Session.GetString("JWToken"));

                TrailsVM objVM = new TrailsVM()
                {
                    CampingParkList = cpList.Select(i => new SelectListItem
                    {
                        Text  = i.Name,
                        Value = i.Id.ToString()
                    }),
                    Trail = obj.Trail
                };

                return(View(objVM));
            }
        }
Example #15
0
        public async Task <IActionResult> Upsert(TrailsViewModel obj)
        {
            if (ModelState.IsValid)
            {
                if (obj.Trail.Id == 0)
                {
                    await _trailRepository.CreateAsync(SD.TrailUrl, obj.Trail, HttpContext.Session.GetString("JWToken"));
                }
                else
                {
                    await _trailRepository.UpdateAsync(SD.NationalParkUrl + obj.Trail.Id, obj.Trail, HttpContext.Session.GetString("JWToken"));
                }
                return(RedirectToAction("Index", "Trails"));
            }
            else
            {
                IEnumerable <NationalPark> npList = await _nationalParkRepository.GetAllAsync(SD.NationalParkUrl, HttpContext.Session.GetString("JWToken"));

                TrailsViewModel objVM = new TrailsViewModel()
                {
                    NationalParkList = npList.Select(i => new SelectListItem
                    {
                        Text  = i.Name,
                        Value = i.Id.ToString()
                    }),
                    Trail = obj.Trail
                };
                return(View(objVM));
            }
        }
Example #16
0
        public async Task <IActionResult> Create(TrailCreateDto model)
        {
            if (ModelState.IsValid)
            {
                var success = await _trailRepo.CreateAsync(_trailUrl, model, HttpContext.Session.GetString("JWToken"));

                if (success)
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError("", "SomeError happens.");
            }
            return(View(model));
        }
Example #17
0
        public async Task <IActionResult> Upsert(TrailVM trailVM)
        {
            var token = HttpContext.Session.GetString("JwToken");

            if (!ModelState.IsValid)
            {
                IEnumerable <NationalPark> nationalParkList = await _npRepository.GetAllAsync(SD.NationalParkAPIPath, token);

                trailVM.NationalParkList = nationalParkList.Select(x => new SelectListItem()
                {
                    Text  = x.Name,
                    Value = x.Id.ToString()
                });

                return(View(trailVM));
            }

            if (trailVM.Trail.Id == 0)
            {
                trailVM.Trail.DateCreated = DateTime.Now;
                var succeed = await _tRepository.CreateAsync(SD.TrailAPIPath, trailVM.Trail, token);

                if (succeed)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                var succeed = await _tRepository.UpdateAsync(SD.TrailAPIPath, trailVM.Trail.Id, trailVM.Trail, token);

                if (succeed)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(NotFound());
                }
            }
        }
Example #18
0
 public async Task <IActionResult> Upsert(TrailsVM obj)
 {
     if (ModelState.IsValid)
     {
         if (obj.Trails.Id == 0)
         {
             await _trailRepo.CreateAsync(SD.TrailAPIPath, obj.Trails);
         }
         else
         {
             await _trailRepo.UpdateAsync(SD.TrailAPIPath + obj.Trails.Id, obj.Trails);
         }
         return(RedirectToAction(nameof(Index)));
     }
     else
     {
         return(View(obj));
     }
 }
 public async Task <IActionResult> Upsert(TrailsVM obj)
 {
     if (ModelState.IsValid)
     {
         if (obj.Trail.Id == 0)
         {
             await _trailRepo.CreateAsync(SD.TrailAPIPath, obj.Trail, HttpContext.Session.GetString("JWTToken"));
         }
         else
         {
             await _trailRepo.UpdateAsync(SD.TrailAPIPath + obj.Trail.Id, obj.Trail, HttpContext.Session.GetString("JWTToken"));
         }
         return(RedirectToAction(nameof(Index)));
     }
     else
     {
         return(View(obj));
     }
 }
Example #20
0
        public async Task <IActionResult> Upsert(TrailsViewModel trailVM)
        {
            if (ModelState.IsValid)
            {
                if (trailVM.Trail.Id == 0)
                {
                    await _trails.CreateAsync(Globals.ApiTrialUrl, trailVM.Trail, HttpContext.Session.GetString("JWToken"));
                }
                else
                {
                    await _trails.UpdateAsync(Globals.ApiTrialUrl, trailVM.Trail, trailVM.Trail.Id, HttpContext.Session.GetString("JWToken"));
                }

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View(trailVM));
            }
        }
Example #21
0
        public async Task <IActionResult> Upsert(TrailVM objVM)
        {
            if (ModelState.IsValid)
            {
                if (objVM.Trail.Id == 0)
                {
                    await _trailRepo.CreateAsync(SD.TrailsApiPath, objVM.Trail, HttpContext.Session.GetString("JWT"));
                }
                else
                {
                    await _trailRepo.UpdateAsync(SD.TrailsApiPath + objVM.Trail.Id, objVM.Trail, HttpContext.Session.GetString("JWT"));
                }

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                objVM.nationalParkList = await _npRepo.GetAllAsync(SD.NationalParkApiPath, HttpContext.Session.GetString("JWT"));

                return(View(objVM));
            }
        }