Example #1
0
        public async Task <IActionResult> Post(TravellersViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View("Form", viewModel));
                }

                await Manager.Save(new Travellers
                {
                    ID_Travellers         = viewModel.ID_Travellers,
                    TX_FirstName          = viewModel.TX_FirstName,
                    TX_SecondName         = viewModel.TX_SecondName,
                    TX_LastName           = viewModel.TX_LastName,
                    TX_SecondLastName     = viewModel.TX_SecondLastName,
                    TX_Phone              = viewModel.TX_Phone,
                    TX_IdentificationCard = viewModel.TX_IdentificationCard,
                    TX_Address            = viewModel.TX_Address
                });

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Error", ex.Message);
                return(View("Form", viewModel));
            }
        }
        public ActionResult Index()
        {
            TravellersViewModel model = null;

            if (this.userProvider.IsAuthenticated())
            {
                var userId = this.userProvider.GetUserId();

                model = new TravellersViewModel()
                {
                    Travellers = this.userService.GetAllRegularUsersExceptLogged(userId).ToList()
                                 .Select(t => new TravellerViewModel(t)).ToList(),
                    LoggedUserId        = userId,
                    UserIsAuthenticated = true
                };
            }
            else
            {
                model = new TravellersViewModel()
                {
                    Travellers = this.userService.GetAllRegularUsers().ToList()
                                 .Select(t => new TravellerViewModel(t)).ToList(),
                    LoggedUserId        = null,
                    UserIsAuthenticated = false
                };
            }

            return(View(model));
        }
Example #3
0
        public async Task <IActionResult> Index()
        {
            TravellersViewModel travellersViewModel = new TravellersViewModel();

            travellersViewModel.Travellers = await Manager.All();

            return(View(travellersViewModel));
        }
Example #4
0
 public IActionResult Get()
 {
     try
     {
         TravellersViewModel travellersViewModel = new TravellersViewModel();
         return(View("Form", travellersViewModel));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
        public ActionResult FilteredTravellers(string searchTerm)
        {
            TravellersViewModel model = null;

            if (string.IsNullOrEmpty(searchTerm))
            {
                if (userProvider.IsAuthenticated())
                {
                    var userId = this.userProvider.GetUserId();
                    model = new TravellersViewModel()
                    {
                        Travellers = this.userService.GetAllRegularUsersExceptLogged(userId)
                                     .ToList().Select(t => new TravellerViewModel(t)),
                        LoggedUserId        = this.userProvider.GetUserId(),
                        UserIsAuthenticated = true
                    };
                }
                else
                {
                    model = new TravellersViewModel()
                    {
                        Travellers          = this.userService.GetAllRegularUsers().ToList().Select(t => new TravellerViewModel(t)),
                        LoggedUserId        = null,
                        UserIsAuthenticated = false
                    };
                }
            }
            else
            {
                model = new TravellersViewModel()
                {
                    Travellers = this.userService.SearchUsersByUsername(searchTerm)
                                 .ToList().Select(t => new TravellerViewModel(t))
                };
                if (userProvider.IsAuthenticated())
                {
                    var userId = this.userProvider.GetUserId();
                    model.LoggedUserId        = this.userProvider.GetUserId();
                    model.UserIsAuthenticated = true;
                }
                else
                {
                    model.LoggedUserId        = null;
                    model.UserIsAuthenticated = false;
                }
            }
            return(PartialView("_FilteredTravellersPartial", model));
        }
Example #6
0
        public async Task <IActionResult> GetUpdate(int id)
        {
            try
            {
                var entity = await Manager.FindById(id);

                TravellersViewModel viewModel = new TravellersViewModel
                {
                    ID_Travellers         = entity.ID_Travellers,
                    TX_FirstName          = entity.TX_FirstName,
                    TX_SecondName         = entity.TX_SecondName,
                    TX_LastName           = entity.TX_LastName,
                    TX_SecondLastName     = entity.TX_SecondLastName,
                    TX_Phone              = entity.TX_Phone,
                    TX_IdentificationCard = entity.TX_IdentificationCard,
                    TX_Address            = entity.TX_Address
                };
                return(View("Form", viewModel));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }