예제 #1
0
        private PersonViewModel createTestData()
        {
            //
            //
            // THIS is KINDA THE SOLUTION DON"T LOOK AT IT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            //
            // ALL YOU NEED TO KNOW IS THAT IT CREATES THE DATA TO PUT ON THE WEBPAGE, WITHOUT NEEDING TO HAVE THE DATA IN THE DATABASE
            //
            //

            PersonViewModel personViewModel = new PersonViewModel();

            var persons = new List<Person> {
                new Person{ID = 1, FirstName="Khechar",LastName="Boorla",Email="*****@*****.**"},
                new Person{ID = 2, FirstName="Nick",LastName="Hill",Email="*****@*****.**"},
                new Person{ID = 3, FirstName="Philly",LastName="TheKid",Email="*****@*****.**"},
                new Person{ID = 4, FirstName="Wyatt",LastName="Earp",Email="*****@*****.**"},
                new Person{ID = 5, FirstName="Michael",LastName="GlueStick",Email="*****@*****.**"},
                new Person{ID = 6, FirstName="Barack",LastName="Obama",Email="*****@*****.**"},
            };

            var events = new List<Event> {
                new Event{ID = 1, Name="Keynote",Room="Legends I",EventDate=DateTime.Parse("2016-02-01"),StartTime=DateTime.Parse("2016-02-01 08:00 AM"),EndTime=DateTime.Parse("2016-02-01 09:00 AM")},
                new Event{ID = 2, Name="Keynote Setup",Room="Legends I",EventDate=DateTime.Parse("2016-02-01"),StartTime=DateTime.Parse("2016-02-01 07:00 AM"),EndTime=DateTime.Parse("2016-02-01 09:00 AM")},
                new Event{ID = 3, Name="Manage Your Fleet",Room="Founders I-II",EventDate=DateTime.Parse("2016-02-01"),StartTime=DateTime.Parse("2016-02-01 09:00 AM"),EndTime=DateTime.Parse("2016-02-01 12:00 PM")},
                new Event{ID = 4, Name="Coaches Corner",Room="Founders III-IV",EventDate=DateTime.Parse("2016-02-01"),StartTime=DateTime.Parse("2016-02-01 04:00 PM"),EndTime=DateTime.Parse("2016-02-01 06:00 PM")},
                new Event{ID = 5, Name="Lunch",Room="Champions I-II",EventDate=DateTime.Parse("2016-02-01"),StartTime=DateTime.Parse("2016-02-01 12:00 PM"),EndTime=DateTime.Parse("2016-02-01 01:00 PM")},
                new Event{ID = 6, Name="Breakfast",Room="Champions I-II",EventDate=DateTime.Parse("2016-02-01"),StartTime=DateTime.Parse("2016-02-01 07:00 AM"),EndTime=DateTime.Parse("2016-02-01 08:00 AM")},
                new Event{ID = 7, Name="Understanding HeavyBid",Room="Champions III-IV",EventDate=DateTime.Parse("2016-02-01"),StartTime=DateTime.Parse("2016-02-01 01:00 PM"),EndTime=DateTime.Parse("2016-02-01 04:00 PM")},
                new Event{ID = 8, Name="How To Move To Mobile",Room="Summit",EventDate=DateTime.Parse("2016-02-01"),StartTime=DateTime.Parse("2016-02-01 01:00 PM"),EndTime=DateTime.Parse("2016-02-01 04:00 PM")},
            };

            var roles = new List<Role> {
                new Role{ID = 1, Name="Attendee"},
                new Role{ID = 2, Name="Speaker"},
            };

            var assignments = new List<Assignment> {
                new Assignment{ID = 1, PersonID=6,EventID=1,StartTime=DateTime.Parse("2016-02-01 08:00 AM"), EndTime=DateTime.Parse("2016-02-01 09:00 AM"), RoleID=2},
                new Assignment{ID = 2, PersonID=5,EventID=1,StartTime=DateTime.Parse("2016-02-01 08:00 AM"), EndTime=DateTime.Parse("2016-02-01 09:00 AM"), RoleID=1},
                new Assignment{ID = 3, PersonID=4,EventID=1,StartTime=DateTime.Parse("2016-02-01 08:00 AM"), EndTime=DateTime.Parse("2016-02-01 09:00 AM"), RoleID=1},
                new Assignment{ID = 4, PersonID=3,EventID=1,StartTime=DateTime.Parse("2016-02-01 08:00 AM"), EndTime=DateTime.Parse("2016-02-01 09:00 AM"), RoleID=1},
                new Assignment{ID = 5, PersonID=2,EventID=1,StartTime=DateTime.Parse("2016-02-01 08:00 AM"), EndTime=DateTime.Parse("2016-02-01 09:00 AM"), RoleID=1},
                new Assignment{ID = 6, PersonID=1,EventID=1,StartTime=DateTime.Parse("2016-02-01 08:00 AM"), EndTime=DateTime.Parse("2016-02-01 09:00 AM"), RoleID=1},

                new Assignment{ID = 7, PersonID=5,EventID=2,StartTime=DateTime.Parse("2016-02-01 07:00 AM"), EndTime=DateTime.Parse("2016-02-01 07:45 AM"), RoleID=1},
                new Assignment{ID = 8, PersonID=4,EventID=2,StartTime=DateTime.Parse("2016-02-01 07:00 AM"), EndTime=DateTime.Parse("2016-02-01 07:45 AM"), RoleID=1},
                new Assignment{ID = 9, PersonID=3,EventID=2,StartTime=DateTime.Parse("2016-02-01 07:00 AM"), EndTime=DateTime.Parse("2016-02-01 07:45 AM"), RoleID=1},
                new Assignment{ID = 10, PersonID=2,EventID=2,StartTime=DateTime.Parse("2016-02-01 07:00 AM"), EndTime=DateTime.Parse("2016-02-01 08:00 AM"), RoleID=1},
                new Assignment{ID = 11, PersonID=1,EventID=2,StartTime=DateTime.Parse("2016-02-01 07:00 AM"), EndTime=DateTime.Parse("2016-02-01 08:00 AM"), RoleID=1},

                new Assignment{ID = 12, PersonID=3,EventID=3,StartTime=DateTime.Parse("2016-02-01 09:00 AM"), EndTime=DateTime.Parse("2016-02-01 12:00 PM"), RoleID=1},
                new Assignment{ID = 13, PersonID=2,EventID=3,StartTime=DateTime.Parse("2016-02-01 09:00 AM"), EndTime=DateTime.Parse("2016-02-01 12:00 PM"), RoleID=1},
                new Assignment{ID = 14, PersonID=4,EventID=3,StartTime=DateTime.Parse("2016-02-01 09:00 AM"), EndTime=DateTime.Parse("2016-02-01 12:00 PM"), RoleID=1},

                new Assignment{ID = 15, PersonID=4,EventID=4,StartTime=DateTime.Parse("2016-02-01 05:00 PM"), EndTime=DateTime.Parse("2016-02-01 06:00 pM"), RoleID=1},
                new Assignment{ID = 16, PersonID=3,EventID=4,StartTime=DateTime.Parse("2016-02-01 04:00 PM"), EndTime=DateTime.Parse("2016-02-01 05:45 PM"), RoleID=1},
            };

            foreach (Person person in persons) {
                person.Assignments = assignments.Where(a => a.PersonID == person.ID).ToList();

                foreach (Assignment assignment in person.Assignments) {
                    assignment.Event = events.Where(e => e.ID == assignment.EventID).SingleOrDefault();
                    assignment.Role = roles.Where(r => r.ID == assignment.RoleID).SingleOrDefault();
                }
            }
            personViewModel.Persons = persons;

            return personViewModel;
        }
예제 #2
0
        // GET: Person
        public ActionResult Index(string search, string option, string SortOrder)
        {
            PersonViewModel personViewModel = new PersonViewModel();
            personViewModel.Persons = Person.getAll();

            //search feature for persons view
            if (search != null && search != "" && option != null)
            {
                if (option == "First Name")
                {
                    List<Person> matchingPersons = db.Persons.Where(s => s.FirstName.Contains(search)).ToList();
                    personViewModel.Persons = matchingPersons;
                }
                else if (option == "Last Name")
                {
                    List<Person> matchingPersons = db.Persons.Where(s => s.LastName.Contains(search)).ToList();
                    personViewModel.Persons = matchingPersons;
                }
                else if (option == "Email")
                {
                    List<Person> matchingPersons = db.Persons.Where(s => s.Email.Contains(search)).ToList();
                    personViewModel.Persons = matchingPersons;
                }
            }
            else
            {
                personViewModel.Persons = Person.getAll();
            }

            //sort feature for persons view
            ViewBag.search = search;
            ViewBag.option = option;
            ViewBag.FirstNameSortParm = SortOrder == "FirstName" ? "FirstName_desc" : "FirstName";
            ViewBag.LastNameSortParm = SortOrder == "LastName" ? "LastName_desc" : "LastName";
            ViewBag.EmailSortParm = SortOrder == "Email" ? "Email_desc" : "Email";

            var Persons = from s in personViewModel.Persons
                         select s;

            switch (SortOrder)
            {
                case "FirstName":
                    Persons = Persons.OrderBy(s => s.FirstName);
                    break;
                case "FirstName_desc":
                    Persons = Persons.OrderByDescending(s => s.FirstName);
                    break;
                case "LastName":
                    Persons = Persons.OrderBy(s => s.LastName);
                    break;
                case "LastName_desc":
                    Persons = Persons.OrderByDescending(s => s.LastName);
                    break;
                case "Email":
                    Persons = Persons.OrderBy(s => s.Email);
                    break;
                case "Email_desc":
                    Persons = Persons.OrderByDescending(s => s.Email);
                    break;
                default:
                    Persons = Persons.OrderBy(s => s.FirstName);
                    break;
            }

            // find and attach events and assignments associated with each person
            foreach (Person person in personViewModel.Persons)
            {
                person.Assignments = Assignment.getAssignmentsByPersonID(person.ID);
                foreach (Assignment assignment in person.Assignments)
                {
                    Event eve = new Event();
                    eve = Event.getEventByID(assignment.EventID);
                    assignment.Event = eve;

                    Role role = new Role();
                    role = Role.getRoleByID(assignment.RoleID);
                    assignment.Role = role;
                }
            }
            //demoMethods();
            //PersonViewModel personViewModel = createTestData();
            personViewModel.Persons = Persons.ToList();
            return View(personViewModel);
        }