示例#1
0
        private void demoMethods()
        {
            /**********************************************************************/
            //
            // the getAll() method
            //
            // getAll() taks no parameters
            // getAll() returns a list of objects. List<objectType>
            //
            //Create an empty list of Persons
            List<Person> persons = new List<Person>();

            //Call the Person.getAll() method and store the return value in our list.
            persons = Person.getAll();

            //output data
            Debug.WriteLine("****** PERSONS ********");
            foreach (Person p in persons) {
                Debug.WriteLine("ID: " + p.ID);
                Debug.WriteLine("Name: " + p.FirstName + " " + p.LastName);
                if (p.Assignments == null) { Debug.WriteLine("Assignments not loaded"); }
                else { Debug.WriteLine("Assignment count: " + p.Assignments.Count.ToString()); }
                Debug.WriteLine("-------------------------------------------------------");
            }

            /**********************************************************************/
            //
            // the getByID(int Id) method
            //
            // getByID(int Id) takes one parameter, an integer value that represents the unique ID of the object to get
            // getAll(int Id) returns one object matching the Id provided. Returns null if no matching object is found.
            //
            //Create a empty object
            Event eve = new Event();

            //Create two dummy event IDs for testing.
            int ExistingEventID = 1;
            int NonExistingEventID = 999;

            //Call the Event.getById(int Id) method and store the return value in our empty event object
            eve = Event.getEventByID(ExistingEventID);

            //output data
            if (eve == null) {
                Debug.WriteLine("****** EVENT DOES NOT EXIST ********");
            }
            else {
                Debug.WriteLine("****** EXISITNG EVENT ********");
                Debug.WriteLine("ID: " + eve.ID);
                Debug.WriteLine("Name: " + eve.Name);
                Debug.WriteLine("Room: " + eve.Room);
                if (eve.Assignments == null) { Debug.WriteLine("Assignments not loaded"); }
                else { Debug.WriteLine("Assignment count: " + eve.Assignments.Count.ToString()); }
                Debug.WriteLine("-------------------------------------------------------");
            }

            //Call the Event.getById(int Id) method with a NonExisting event id. The return value wil be null.
            eve = Event.getEventByID(NonExistingEventID);

            //output data
            if (eve == null) {
                Debug.WriteLine("****** EVENT DOES NOT EXIST ********");
            }
        }
示例#2
0
        public static Event getEventByID(int eventID)
        {
            Event eve = new Event();

            using (var sc = new SchedulerContext())
            {
                eve = sc.Events.Where(e => e.ID == eventID).SingleOrDefault();
            }

            return eve;
        }
示例#3
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);
        }