Exemple #1
0
        public static Role getRoleByID(int roleID)
        {
            Role role = new Role();

            using (var sc = new SchedulerContext()) {
                role = sc.Roles.Where(r => r.ID == roleID).SingleOrDefault();
            }
            return role;
        }
Exemple #2
0
        public static Role getRoleByName(string Name)
        {
            Role role = new Role();

            using (var sc = new SchedulerContext())
            {
                role = sc.Roles.Where(r => r.Name == Name).SingleOrDefault();
            }
            return role;
        }
Exemple #3
0
        public void Upload(string path, TextFieldParser parser, string EntityType)
        {
            Event eve = new Event();
            Person person = new Person();
            Assignment assignment = new Assignment();
            Role role = new Role();

            switch (EntityType)
            {
                case "Event":
                    {
                        while (!parser.EndOfData)
                        {
                            //Process row
                            string[] fields = parser.ReadFields();

                            eve.Name = fields[0];
                            eve.Room = fields[1];
                            eve.EventDate = Convert.ToDateTime(fields[2]);
                            eve.StartTime = DateTime.ParseExact(fields[3], "HH:mm", System.Globalization.CultureInfo.CurrentCulture);
                            eve.EndTime = DateTime.ParseExact(fields[4], "HH:mm", System.Globalization.CultureInfo.CurrentCulture);

                            Event SameEve = db.Events.Where(i => i.Name == eve.Name).FirstOrDefault();

                            if (SameEve == null)
                            {
                                db.Events.Add(eve);
                                db.SaveChanges();
                            }
                            /*else if (SameEve.Name == eve.Name)
                            {
                                db.Events.Attach(SameEve);
                                SameEve.Quantity += ingredient.Quantity;
                                db.SaveChanges();
                            }*/
                        }
                        parser.Close();
                        break;
                    }
                case "Person":
                    {
                        while (!parser.EndOfData)
                        {
                            string[] fields = parser.ReadFields();

                            person.FirstName = fields[0];
                            person.LastName = fields[1];
                            person.Email = fields[2];

                            Person SamePerson = db.Persons.Where(i => i.FirstName == person.FirstName && i.LastName == person.LastName).FirstOrDefault();

                            if(SamePerson == null)
                            {
                                db.Persons.Add(person);
                                db.SaveChanges();
                            }
                            //else if (SamePerson.LastName == person.LastName && SamePerson.FirstName == person.FirstName)
                            //{
                            //    db.SaveChanges();
                            //}
                        }
                        parser.Close();
                        break;
                    }
                case "Assignment":
                    {
                        while (!parser.EndOfData)
                        {
                            string[] fields = parser.ReadFields();

                            assignment.Event.Name = fields[0];
                            assignment.Person.FirstName = fields[1];
                            assignment.Role.Name = fields[2];
                            assignment.Event.StartTime = DateTime.ParseExact(fields[3], "HH:mm", System.Globalization.CultureInfo.CurrentCulture);
                            assignment.Event.EndTime = DateTime.ParseExact(fields[4], "HH:mm", System.Globalization.CultureInfo.CurrentCulture);

                            Assignment SameAssignment = db.Assignments.Where(i => i.Event.Name == assignment.Event.Name && i.Person.FirstName == assignment.Person.FirstName && i.Role.Name == assignment.Role.Name).FirstOrDefault();

                            if(SameAssignment == null)
                            {
                                db.Assignments.Add(assignment);
                                db.SaveChanges();
                            }
                            else if (SameAssignment.Event.Name == assignment.Event.Name && SameAssignment.Person.FirstName == assignment.Person.FirstName && SameAssignment.Role.Name == assignment.Role.Name)
                            {
                                db.SaveChanges();
                            }
                        }
                        parser.Close();
                        break;
                    }
                case "Role":
                    {
                        while (!parser.EndOfData)
                        {
                            string[] fields = parser.ReadFields();

                            role.Name = fields[0];

                            Role SameRole = db.Roles.Where(i => i.Name == role.Name).FirstOrDefault();

                            if(SameRole == null)
                            {
                                db.Roles.Add(role);
                                db.SaveChanges();
                            }
                            else if(SameRole.Name == role.Name)
                            {
                                db.SaveChanges();
                            }
                        }
                        parser.Close();
                        break;
                    }
            }
        }
        // GET: Person
        public ActionResult Index(string SortOrder, string option, string search, DateTime? SearchDateTime)
        {
            EventViewModel eventViewModel = new EventViewModel(); //this constructor will return an object that conains a list of all events a list of roles... see the EventViewModel class

            //did the user type in a search term?
            if (search != null && search != "" && option != null)
            {
                //determine what field they are searching; i.e. Name, Room, etc...
                if (option == "Name")
                {
                    //  1. get a list of events whose name field matches the search term
                    List<Event> matchingEvents = db.Events.Where(s => s.Name.Contains(search)).ToList();
                    //  2. replace the list of all events in the eventViewModel with the list of matching events
                    eventViewModel.Events = matchingEvents;
                }
                else if (option == "Room")
                {
                    List<Event> matchingEvents = db.Events.Where(s => s.Room.Contains(search)).ToList();
                    eventViewModel.Events = matchingEvents;
                }
                else if (option == "Date")
                {
                    List<Event> matchingEvents = new List<Event>();
                    foreach (Event e in eventViewModel.Events)
                    {
                        if (e.EventDate.ToString().Contains(search) == true)
                        {
                            matchingEvents.Add(e);
                        }
                    }
                    eventViewModel.Events = matchingEvents;
                }
                else if (option == "Start Time")
                {
                    List<Event> matchingEvents = new List<Event>();
                    foreach (Event e in eventViewModel.Events)
                    {
                        if (e.StartTime.ToString().Contains(search) == true)
                        {
                            matchingEvents.Add(e);
                        }
                    }
                    eventViewModel.Events = matchingEvents;
                }
                else if (option == "End Time")
                {
                    List<Event> matchingEvents = new List<Event>();
                    foreach (Event e in eventViewModel.Events)
                    {
                        if (e.EndTime.ToString().Contains(search) == true)
                        {
                            matchingEvents.Add(e);
                        }
                    }
                    eventViewModel.Events = matchingEvents;
                }
            }
            else
            {
                eventViewModel.Events = Event.getAll();
            }

            ViewBag.search = search;
            ViewBag.option = option;
            ViewBag.NameSortParm = SortOrder == "Name" ? "Name_desc" : "Name";
            ViewBag.RoomSortParm = SortOrder == "Room" ? "Room_desc" : "Room";
            ViewBag.DateSortParm = SortOrder == "Date" ? "Date_desc" : "Date";
            ViewBag.StartTimeSortParm = SortOrder == "StartTime" ? "StartTime_desc" : "StartTime";
            ViewBag.EndTimeSortParm = SortOrder == "EndTime" ? "EndTime_desc" : "EndTime";

            var Events = from s in eventViewModel.Events
                select s;

            switch (SortOrder)
            {
                case "Name":
                    //eventViewModel. Events = eventViewModel.Events.OrderBy(s => s.Name).ToList();
                    Events = Events.OrderBy(s => s.Name);
                    break;
                case "Name_desc":
                    //eventViewModel.Events = eventViewModel.Events.OrderBy(s => s.Name).ToList();
                    Events = Events.OrderByDescending(s => s.Name);
                    break;
                case "Room":
                    //eventViewModel.Events = eventViewModel.Events.OrderBy(s => s.Name).ToList();
                    Events = Events.OrderBy(s => s.Room);
                    break;
                case "Room_desc":
                    //eventViewModel.Events = eventViewModel.Events.OrderBy(s => s.Name).ToList();
                    Events = Events.OrderByDescending(s => s.Room);
                    break;
                case "Date":
                    //eventViewModel.Events = eventViewModel.Events.OrderBy(s => s.Name).ToList();
                    Events = Events.OrderBy(s => s.EventDate);
                    break;
                case "Date_desc":
                    //eventViewModel.Events = eventViewModel.Events.OrderBy(s => s.Name).ToList();
                    Events = Events.OrderByDescending(s => s.EventDate);
                    break;
                case "StartTime":
                    //eventViewModel.Events = eventViewModel.Events.OrderBy(s => s.Name).ToList();
                    Events = Events.OrderBy(s => s.StartTime);
                    break;
                case "StartTime_desc":
                    //eventViewModel.Events = eventViewModel.Events.OrderBy(s => s.Name).ToList();
                    Events = Events.OrderByDescending(s => s.StartTime);
                    break;
                case "EndTime":
                    //eventViewModel.Events = eventViewModel.Events.OrderBy(s => s.Name).ToList();
                    Events = Events.OrderBy(s => s.EndTime);
                    break;
                case "EndTime_desc":
                    //eventViewModel.Events = eventViewModel.Events.OrderBy(s => s.Name).ToList();
                    Events = Events.OrderByDescending(s => s.EndTime);
                    break;
                default:
                    //eventViewModel.Events = eventViewModel.Events.OrderBy(s => s.Name).ToList();
                    Events = Events.OrderBy(s => s.Name);
                    break;
            }
            //eventViewModel.Events.ToList();

            foreach (Event eve in eventViewModel.Events)
            {
                eve.Assignments = Assignment.getAssignmentsByEvent(eve.ID);

                foreach (Assignment assignment in eve.Assignments)
                {
                    Person person = new Person();
                    person = Person.getPersonByID(assignment.PersonID);
                    assignment.Person = person;

                    Role role = new Role();
                    role = Role.getRoleByID(assignment.RoleID);
                    assignment.Role = role;
                }
            }

            eventViewModel.Events = Events.ToList();

            return View(eventViewModel);
        }
        // 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);
        }