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));
            }
        }
        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));
            }
        }
        public async Task <IActionResult> Upsert(int?id)
        {
            IEnumerable <NationalPark> npList = await _nationalParkRepository.GetAllAsync(SD.NationalParkUrl, HttpContext.Session.GetString("JWToken"));

            TrailsViewModel viewModel = new TrailsViewModel()
            {
                NationalParkList = npList.Select(np => new SelectListItem
                {
                    Text  = np.Name,
                    Value = np.Id.ToString()
                })
            };

            if (id == null)
            {
                return(View(viewModel));
            }

            viewModel.Trail = await _trailRepository.GetAsync(SD.TrailUrl, id.GetValueOrDefault(), HttpContext.Session.GetString("JWToken"));

            if (viewModel.Trail == null)
            {
                return(NotFound());
            }

            return(View(viewModel));
        }
Exemple #4
0
        public async Task <IActionResult> Upsert(TrailsViewModel obje)
        {
            if (ModelState.IsValid)
            {
                if (obje.Trail.Id == 0)
                {
                    await this.trailRepository.CreateAsync(StaticDetails.TrailAPIPath, obje.Trail, HttpContext.Session.GetString("JWToken"));
                }
                else
                {
                    await this.trailRepository.UpdateAsync(StaticDetails.TrailAPIPath + obje.Trail.Id, obje.Trail, HttpContext.Session.GetString("JWToken"));
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                IEnumerable <NationalPark> nationalParkList = await this.nationalParkRepository.GetAllAsync(StaticDetails.NationalParkAPIPath, HttpContext.Session.GetString("JWToken"));

                TrailsViewModel objeViewModel = new TrailsViewModel()
                {
                    NationalParkList = nationalParkList.Select(İ => new SelectListItem
                    {
                        Text  = İ.Name,
                        Value = İ.Id.ToString()
                    }),
                    Trail = obje.Trail
                };

                return(View(objeViewModel));
            }
        }
        public async Task <IActionResult> Upsert(int?id)
        {
            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 = new Trail()
            };

            if (id == null)
            {
                //FLOW: True for create
                return(View(objVM));
            }

            //FLOW: Update method from here
            objVM.Trail = await _trailRepo.GetAsync(Static.TrailAPIPath, id.GetValueOrDefault(), HttpContext.Session.GetString("JWToken"));

            if (objVM.Trail == null)
            {
                return(NotFound());
            }
            else
            {
                return(View(objVM));
            }
        }
Exemple #6
0
        public async Task <IActionResult> Upsert(int?id)
        {
            IEnumerable <NationalPark> nationalParkList = await this.nationalParkRepository.GetAllAsync(StaticDetails.NationalParkAPIPath, HttpContext.Session.GetString("JWToken"));

            TrailsViewModel objeViewModel = new TrailsViewModel()
            {
                NationalParkList = nationalParkList.Select(İ => new SelectListItem
                {
                    Text  = İ.Name,
                    Value = İ.Id.ToString()
                }),
                Trail = new Trail()
            };

            if (id == null)
            {
                return(View(objeViewModel));
            }
            // after pressed to update or edit button cursor will come here
            objeViewModel.Trail = await this.trailRepository.GetAsync(StaticDetails.TrailAPIPath, id.GetValueOrDefault(), HttpContext.Session.GetString("JWToken"));

            if (objeViewModel == null)
            {
                return(NotFound());
            }
            return(View(objeViewModel));
        }
Exemple #7
0
        public async Task <IActionResult> Upsert(TrailsViewModel 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);

                TrailsViewModel objVM = new TrailsViewModel()
                {
                    NationalParkList = npList.Select(i => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem
                    {
                        Text  = i.Name,
                        Value = i.Id.ToString()
                    }),
                    Trail = obj.Trail
                };
                return(View(objVM));
            }
        }
Exemple #8
0
        public async Task <IActionResult> Upsert(int?id)
        {
            IEnumerable <NationalPark> npList = await _npRepo.GetAllAsync(SD.NationalParkAPIPath);

            TrailsViewModel objVM = new TrailsViewModel()
            {
                NationalParkList = npList.Select(i => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem
                {
                    Text  = i.Name,
                    Value = i.Id.ToString()
                }),
                Trail = new Trail()
            };


            if (id == null)
            {
                return(View(objVM));
            }
            objVM.Trail = await _trailRepo.GetAsync(SD.TrailAPIPath, id.GetValueOrDefault());

            if (objVM.Trail == null)
            {
                return(NotFound());
            }
            return(View(objVM));
        }
Exemple #9
0
        public async Task <IActionResult> Upsert(int?id)
        {
            IEnumerable <NationalPark> npList = await _parks.GetAllAsync(Globals.ApiNpUrl, HttpContext.Session.GetString("JWToken"));

            TrailsViewModel trailVM = new TrailsViewModel()
            {
                NationalParkList = npList.Select(i => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem
                {
                    Text  = i.Name,
                    Value = i.Id.ToString()
                })
            };

            if (id == null)
            {
                return(View(trailVM));
            }

            trailVM.Trail = await _trails.GetAsync(Globals.ApiTrialUrl, id.GetValueOrDefault(), HttpContext.Session.GetString("JWToken"));

            if (trailVM.Trail is null)
            {
                return(NotFound());
            }

            return(View(trailVM));
        }
Exemple #10
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));
            }
        }