Exemplo n.º 1
0
        public IActionResult ConfirmationPage(EventRegistration eventRegistration, int eventId, string Id)
        {
            var   counter     = 0;
            Event passedEvent = context.Events
                                .FirstOrDefault(x => x.EventID == eventId);

            if (ModelState.IsValid)
            {
                //Saving the event registration data to the database
                try
                {
                    registrationRepository.SaveEventRegistration(eventRegistration);
                    counter++;
                }
                catch
                {
                    //handles exception for unique key pair constraint
                }

                //creating viewModel object to return all event signed-up data for displaying on confirmation
                //page and dashboard.
                var viewModel = new SignedUpEventsViewModel
                {
                    EventRegistration = eventRegistration,
                    EventId           = eventId,
                    Event             = context.Events
                                        .Include(i => i.Location)
                                        .FirstOrDefault(x => x.EventID == eventId),
                    Location = context.Locations
                               .FirstOrDefault(a => a.LocationID == eventId),
                    Locations = context.Locations.ToList(),
                    UserId    = Id,
                };
                //returns the confirmation page viewmodel data
                if (counter > 0)
                {
                    int newSignUpNum = passedEvent.NumVolunteersSignedUp + 1;
                    passedEvent.NumVolunteersSignedUp = newSignUpNum;
                    int newSignUpNum2 = passedEvent.NumVolunteersNeeded - 1;
                    passedEvent.NumVolunteersNeeded = newSignUpNum2;
                    context.SaveChanges();
                    return(View("ConfirmationPage", viewModel));
                }
                else
                {
                    ViewBag.ErrorMessage = "You have already signed up for this event. You can view this event registration in your volunteer dashboard.";
                    return(View("EventInfoPage", viewModel));
                }
            }
            else
            {
                // there is something wrong with the data values
                return(View(eventRegistration));
            }
        }
        public ViewResult EventInfoPage(int eventId)
        {
            //inserting viewmodel object
            var viewModel = new SignedUpEventsViewModel
            {
                Event = context.Events
                        .Include(i => i.Location)
                        .FirstOrDefault(x => x.EventID == eventId),
                Events = context.Events.ToList(),
            };

            //Returns viewModel object with Event data
            return(View(viewModel));
        }
Exemplo n.º 3
0
        public async Task <ViewResult> ConfirmationPage(int eventId, string Id)
        {
            //inserting user object and obtaining userID from usermanager identity class
            var user = await userManager.FindByIdAsync(Id);

            //inserting new EventRegistration Object
            EventRegistration myEvent = new EventRegistration();

            var viewModel = new SignedUpEventsViewModel
            {
                EventRegistration = myEvent,
                Event             = repository.Events
                                    .FirstOrDefault(x => x.EventID == eventId),
                UserId = Id
            };

            //Returns viewModel object with EventRegistration data
            return(View(viewModel));
        }
Exemplo n.º 4
0
        //Method that displays page with table of events. It only shows events that occur in the future
        //and that are considered active.
        public ViewResult EventSignUp(int eventId)
        {
            //this is the EventRegistration object where the EventID and UserID are stored.
            //EventRegistration myEvent = new EventRegistration();

            //this is the viewModel. I used one viewmodel for the sign up process for consistency.
            var viewModel = new SignedUpEventsViewModel
            {
                //EventRegistration = myEvent,
                Event = context.Events
                        .Include(i => i.Location)
                        //.Where(x => x.isEventActive == true && x.EventDate > DateTime.Now),
                        .FirstOrDefault(x => x.EventID == eventId),
                Events    = context.Events.Where(x => x.isEventActive == true && x.EventDate > DateTime.Now).ToList(),
                Locations = context.Locations.ToList()
            };


            //Returns viewModel object with EventRegistration data
            return(View(viewModel));
        }
        //this is the index/volunteer events tabs. It displays data for the events the volunteer
        //is signed up for.
        public async Task <ViewResult> Index(string userId, int Id)
        {
            //referencing identity usermanger class passed into the constructor. This retrieves
            //the userID from the IdentityDbContext.
            var user = await userManager.FindByIdAsync(userId);

            //Create viewmodel object for the view
            var viewModel = new SignedUpEventsViewModel()
            {
                //gets an event instance to reference single events
                Event = eventRepository.Events
                        .FirstOrDefault(a => a.EventID == Id),
                //provides list of locations
                Locations = context.Locations.ToList(),
                //list of event registrations
                EventRegistrations = context.EventRegistrations.ToList(),
                //event list view
                Events = context.Events.ToList(),
                UserId = userId
            };

            //returns all the items passed into the viewmodel object to refence in the view.
            return(View(viewModel));
        }