Example #1
0
        public static Person getPersonByID(int? personID)
        {
            if (personID == null) { return null;  }

            Person person = new Person();

            using (var sc = new SchedulerContext()) {
                person = sc.Persons.Where(p => p.ID == personID).SingleOrDefault();
            }

            return person;
        }
Example #2
0
        // 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);
        }
Example #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;
                    }
            }
        }