Exemplo n.º 1
0
        public List <Subject> GetFilteredScheduleSubjects(Schedule selectedSchedule, string day)
        {
            List <Subject> subjects = new List <Subject>();

            using (var context = new SchedulesEntities1())
            {
                var query = (from p in context.Schedules.Include("Subjects")
                             where p.Id == selectedSchedule.Id
                             select p).FirstOrDefault();


                foreach (var subject in query.Subjects)
                {
                    var query2 = (from p in context.Subjects.Include("Durations").Include("Professors").Include("Halls")
                                  where p.Id == subject.Id
                                  select p).FirstOrDefault();

                    foreach (var duration in query2.Durations)
                    {
                        if (duration.Day == day)
                        {
                            subjects.Add(query2);
                        }
                    }
                }
            }

            return(subjects);
        }
Exemplo n.º 2
0
 public List <Schedule> GetSchedules(User user)
 {
     using (var context = new SchedulesEntities1())
     {
         return(context.Schedules.Where(x => x.User.Id == user.Id).ToList());
     }
 }
 public List <Subject> GetAllSubjects()
 {
     using (var context = new SchedulesEntities1())
     {
         return(context.Subjects.ToList());
     }
 }
        public void CreateSubject(Subject subject)
        {
            using (var context = new SchedulesEntities1())
            {
                Subject newSubject = new Subject
                {
                    Name        = subject.Name,
                    Ects        = subject.Ects,
                    Description = subject.Description,
                    Durations   = subject.Durations
                };

                Schedule  newSchedule  = subject.Schedules.First();
                Professor newProfessor = subject.Professors.First();
                Hall      newHall      = subject.Halls.First();

                context.Schedules.Attach(newSchedule);
                context.Professors.Attach(newProfessor);
                context.Halls.Attach(newHall);

                newSubject.Schedules.Add(newSchedule);
                newSubject.Professors.Add(newProfessor);
                newSubject.Halls.Add(newHall);

                context.Subjects.Add(newSubject);

                context.SaveChanges();
            }
        }
        public void UpdateSubject(Subject subject)
        {
            using (var context = new SchedulesEntities1())
            {
                context.Subjects.Attach(subject);

                context.Entry(subject).State = EntityState.Modified;

                context.SaveChanges();

                context.Entry(subject).State = EntityState.Detached;
            }
        }
Exemplo n.º 6
0
        public void DeleteHall(Hall hall)
        {
            using (var context = new SchedulesEntities1())
            {
                var deletedHall = context.Halls.SingleOrDefault(x => x.Id == hall.Id);

                if (deletedHall != null)
                {
                    context.Halls.Remove(deletedHall);
                }

                context.SaveChanges();
            }
        }
Exemplo n.º 7
0
        public void CreateHall(Hall hall)
        {
            using (var context = new SchedulesEntities1())
            {
                Hall newHall = new Hall
                {
                    Name  = hall.Name,
                    Seats = hall.Seats
                };

                context.Halls.Add(newHall);
                context.SaveChanges();
            }
        }
        public List <Professor> GetAllProfessors()
        {
            List <Professor> professors = new List <Professor>();

            using (var context = new SchedulesEntities1())
            {
                foreach (var professor in context.Professors)
                {
                    professors.Add(professor);
                }
            }

            return(professors);
        }
        public void DeleteProfessor(Professor professor)
        {
            using (var context = new SchedulesEntities1())
            {
                var deletedProfessor = context.Professors.SingleOrDefault(x => x.Id == professor.Id);

                if (deletedProfessor != null)
                {
                    context.Professors.Remove(deletedProfessor);
                }

                context.SaveChanges();
            }
        }
        public void DeleteSubject(Subject subject)
        {
            using (var context = new SchedulesEntities1())
            {
                var deletedSubject = context.Subjects.SingleOrDefault(x => x.Id == subject.Id);

                if (deletedSubject != null)
                {
                    context.Subjects.Remove(deletedSubject);
                }

                context.SaveChanges();
            }
        }
Exemplo n.º 11
0
        public void DeleteSchedule(Schedule selectedSchedule)
        {
            using (var context = new SchedulesEntities1())
            {
                var deletedSchedule = context.Schedules.SingleOrDefault(x => x.Id == selectedSchedule.Id);

                if (deletedSchedule != null)
                {
                    context.Schedules.Remove(deletedSchedule);
                }

                context.SaveChanges();
            }
        }
Exemplo n.º 12
0
        public List <Hall> GetAllHalls()
        {
            List <Hall> halls = new List <Hall>();

            using (var context = new SchedulesEntities1())
            {
                foreach (Hall hall in context.Halls)
                {
                    halls.Add(hall);
                }
            }

            return(halls);
        }
        public void DeleteProfile(User user)
        {
            using (var context = new SchedulesEntities1())
            {
                var deletedUser = context.Users.SingleOrDefault(x => x.Id == user.Id);

                if (deletedUser != null)
                {
                    context.Users.Remove(deletedUser);
                }

                context.SaveChanges();
            }
        }
        public void CreateProfessor(Professor professor)
        {
            using (var context = new SchedulesEntities1())
            {
                Professor newProfessor = new Professor
                {
                    Name    = professor.Name,
                    Surname = professor.Surname,
                    Email   = professor.Email
                };

                context.Professors.Add(newProfessor);
                context.SaveChanges();
            }
        }
Exemplo n.º 15
0
        public void CreateSchedule(User user, string name)
        {
            using (var context = new SchedulesEntities1())
            {
                Schedule newSchedule = new Schedule
                {
                    Name   = name,
                    IdUser = user.Id
                };

                context.Schedules.Add(newSchedule);

                context.SaveChanges();
            }
        }
        public void CreateProfile(User user)
        {
            using (var context = new SchedulesEntities1())
            {
                User newUser = new User
                {
                    Username = user.Username,
                    Password = user.Password,
                    Email    = user.Email
                };

                context.Users.Add(newUser);
                context.SaveChanges();
            }
        }
Exemplo n.º 17
0
        public void UpdateHall(Hall hall)
        {
            using (var context = new SchedulesEntities1())
            {
                var updatedHall = context.Halls.SingleOrDefault(x => x.Id == hall.Id);

                if (updatedHall != null)
                {
                    updatedHall.Name  = hall.Name;
                    updatedHall.Seats = hall.Seats;
                }

                context.SaveChanges();
            }
        }
        public void UpdateProfessor(Professor professor)
        {
            using (var context = new SchedulesEntities1())
            {
                var updatedProfessor = context.Professors.SingleOrDefault(x => x.Id == professor.Id);

                if (updatedProfessor != null)
                {
                    updatedProfessor.Name    = professor.Name;
                    updatedProfessor.Surname = professor.Surname;
                    updatedProfessor.Email   = professor.Email;
                }

                context.SaveChanges();
            }
        }
        public void UpdateProfile(User user)
        {
            using (var context = new SchedulesEntities1())
            {
                var updatedUser = context.Users.SingleOrDefault(x => x.Id == user.Id);

                if (updatedUser != null)
                {
                    updatedUser.Username = user.Username;
                    updatedUser.Password = user.Password;
                    updatedUser.Email    = user.Email;
                }

                context.SaveChanges();
            }
        }
Exemplo n.º 20
0
        public User CheckLoginCredentials(string username, string password)
        {
            User currentUser = new User();

            using (var context = new SchedulesEntities1())
            {
                foreach (var user in context.Users)
                {
                    if (user.Username.ToString() == username && user.Password.ToString() == password)
                    {
                        currentUser = user;
                    }
                }
            }

            return(currentUser);
        }
Exemplo n.º 21
0
        public List <Subject> GetSelectedScheduleSubjects(Schedule selectedSchedule)
        {
            List <Subject> subjects = new List <Subject>();

            using (var context = new SchedulesEntities1())
            {
                var query = (from p in context.Schedules.Include("Subjects")
                             where p.Id == selectedSchedule.Id
                             select p).FirstOrDefault();

                foreach (var subject in query.Subjects)
                {
                    subjects.Add(subject);
                }
            }

            return(subjects);
        }