Exemplo n.º 1
0
        public IActionResult Add(ManagePlannerViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var editingCount = this.getAddingCount(viewModel);

                if (editingCount > 1)
                {
                    TempData["ErrorMessage"] = "You can only add one item at a time.";
                    return(View("Manage", this.createManagePlannerViewModel(viewModel)));
                }
                else if (this.isMissingAccommodationName(viewModel.AccommodationToAdd))
                {
                    var propertyKey       = nameof(viewModel.AccommodationToAdd);
                    var accommodationName = nameof(viewModel.AccommodationToAdd.Name);
                    ModelState.AddModelError($"{propertyKey}.{accommodationName}", "Please enter a name.");
                    return(View("Manage", this.createManagePlannerViewModel(viewModel)));
                }
                else if (editingCount == 0)
                {
                    TempData["ErrorMessage"] = "You haven't added anything.";
                    return(View("Manage", this.createManagePlannerViewModel(viewModel)));
                }

                this.addAndCreateMessage(viewModel);

                return(RedirectToAction("List", "Vacation"));
            }
            else
            {
                return(View("Manage", this.createManagePlannerViewModel(viewModel)));
            }
        }
Exemplo n.º 2
0
        private void deleteAndCreateMessage(ManagePlannerViewModel viewModel)
        {
            try
            {
                var isDeletingAccommodation = viewModel.AccommodationToDelete?.AccommodationId > 0;
                var isDeletingActivity      = viewModel.ActivityToDelete?.ActivityId > 0;
                var isDeletingLocation      = viewModel.LocationToDelete?.LocationId > 0;

                if (isDeletingAccommodation)
                {
                    this.deleteAccommodation(viewModel.AccommodationToDelete);
                }
                else if (isDeletingActivity)
                {
                    deleteActivity(viewModel.ActivityToDelete);
                }
                else if (isDeletingLocation)
                {
                    deleteLocation(viewModel.LocationToDelete);
                }
            }
            catch (Exception err)
            {
                this.addErrorMessage(err.Message);
            }
        }
Exemplo n.º 3
0
        private void addAndCreateMessage(ManagePlannerViewModel viewModel)
        {
            try
            {
                var isAddingAccommodation = !string.IsNullOrEmpty(viewModel.AccommodationToAdd.Name);
                var isAddingActivity      = !string.IsNullOrEmpty(viewModel.ActivityToAdd.Name);
                var isAddingLocation      = !string.IsNullOrEmpty(viewModel.LocationToAdd.Name);

                if (isAddingAccommodation)
                {
                    this.addAccommodation(viewModel.AccommodationToAdd);
                }
                else if (isAddingActivity)
                {
                    this.addActivity(viewModel.ActivityToAdd);
                }
                else if (isAddingLocation)
                {
                    this.addLocation(viewModel.LocationToAdd);
                }
            }
            catch (Exception err)
            {
                this.addErrorMessage(err.Message);
            }
        }
Exemplo n.º 4
0
        private int getDeletingCount(ManagePlannerViewModel viewModel)
        {
            var totalDeleting = 0;

            totalDeleting += viewModel.AccommodationToDelete.AccommodationId > 0 ? 1 : 0;
            totalDeleting += viewModel.ActivityToDelete.ActivityId > 0 ? 1 : 0;
            totalDeleting += viewModel.LocationToDelete.LocationId > 0 ? 1 : 0;

            return(totalDeleting);
        }
Exemplo n.º 5
0
        private int getAddingCount(ManagePlannerViewModel viewModel)
        {
            var totalEditing = 0;

            totalEditing += string.IsNullOrEmpty(viewModel.AccommodationToAdd.Name) == true ? 0 : 1;
            totalEditing += string.IsNullOrEmpty(viewModel.ActivityToAdd.Name) == true ? 0 : 1;
            totalEditing += string.IsNullOrEmpty(viewModel.LocationToAdd.Name) == true ? 0 : 1;

            return(totalEditing);
        }
Exemplo n.º 6
0
 private ManagePlannerViewModel createManagePlannerViewModel(ManagePlannerViewModel prevViewModel)
 {
     if (prevViewModel == null)
     {
         return(new ManagePlannerViewModel()
         {
             AccommodationToAdd = new Accommodation(),
             ActivityToAdd = new Activity(),
             LocationToAdd = new Location(),
             LocationToDelete = new Location(),
             AccommodationToDelete = new Accommodation(),
             ActivityToDelete = new Activity(),
             Locations = data.Locations.List(new QueryOptions <Location>()
             {
                 OrderBy = l => l.Name
             }),
             Accomodations = data.Accommodations.List(new QueryOptions <Accommodation>()
             {
                 OrderBy = a => a.Name
             }),
             Activities = data.Activities.List(new QueryOptions <Activity>()
             {
                 OrderBy = a => a.Name
             })
         });
     }
     else
     {
         return(new ManagePlannerViewModel()
         {
             AccommodationToAdd = prevViewModel.AccommodationToAdd,
             ActivityToAdd = prevViewModel.ActivityToAdd,
             LocationToAdd = prevViewModel.LocationToAdd,
             LocationToDelete = prevViewModel.LocationToDelete,
             AccommodationToDelete = prevViewModel.AccommodationToDelete,
             ActivityToDelete = prevViewModel.ActivityToDelete,
             Locations = data.Locations.List(new QueryOptions <Location>()
             {
                 OrderBy = l => l.Name
             }),
             Accomodations = data.Accommodations.List(new QueryOptions <Accommodation>()
             {
                 OrderBy = a => a.Name
             }),
             Activities = data.Activities.List(new QueryOptions <Activity>()
             {
                 OrderBy = a => a.Name
             })
         });
     }
 }
Exemplo n.º 7
0
        public IActionResult Delete(ManagePlannerViewModel viewModel)
        {
            var deletingCount = this.getDeletingCount(viewModel);

            if (deletingCount > 1)
            {
                TempData["ErrorMessage"] = "You can only delete one item at a time.";
                return(RedirectToAction("Manage"));
            }
            else if (deletingCount == 0)
            {
                TempData["ErrorMessage"] = "You haven't selected anything to delete.";
                return(View("Manage", this.createManagePlannerViewModel(viewModel)));
            }

            this.deleteAndCreateMessage(viewModel);

            return(RedirectToAction("List", "Vacation"));
        }