Ejemplo n.º 1
0
        public ActionResult CreateNews(NewsView model)
        {
            USOSContext context = this.initContext();

            if (!ModelState.IsValid)
            {
                ViewBag.Message = "Dodano";
                return(View(model));
            }

            using (context)
            {
                News Obj = new News();

                if (context.News.Any(x => x.ID == model.ID))
                {
                    ModelState.AddModelError("", "Ta nazwa już istnieje");
                    return(View(model));
                }
                Obj.Text   = model.Text;
                Obj.Header = model.Header;
                Obj.Date   = DateTime.Now;

                ViewBag.Message = "Dodano";
                context.News.Add(Obj);
                context.SaveChanges();
            }
            return(RedirectToAction("News"));
        }
Ejemplo n.º 2
0
 public ActionResult EditMark(LessonStudentMarkView model)
 {
     USOSContext context = this.initContext();
     LessonStudentMark studentmark = null;
     Mark mark = context.Mark.Where(x => x.ID == model.MarkID).First();
     AppUser user = context.Users.Where(x => x.UserName == model.Username).First();
     Lesson lesson = context.Lesson.Where(x => x.ID == model.LessonID).First();
     var query = context.LessonStudentMark.Where(x => x.Lesson.ID == model.LessonID && x.Username.UserName == model.Username).Include(x => x.Mark) ;        
     if (query.Count() != 0)
     {
        studentmark = query.First();
     }
     if (studentmark == null)
     {
         studentmark = new LessonStudentMark();
         studentmark.Mark = mark;
         studentmark.Lesson = lesson;
         studentmark.Username = user;
         context.LessonStudentMark.Add(studentmark);
         context.Entry(studentmark.Lesson).State = EntityState.Unchanged;
         context.Entry(studentmark.Username).State = EntityState.Unchanged;
     }
     else
     {
         studentmark.Mark = mark;
         context.LessonStudentMark.Update(studentmark);
     }
     context.SaveChanges();
     return RedirectToAction("MarkLecturer", "Mark");
 }
Ejemplo n.º 3
0
        public ActionResult EditNews(NewsView model)
        {
            USOSContext context = this.initContext();

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (context)
            {
                int id = model.ID;


                News Obj = context.News.Find(id);


                if (context.News.Where(x => x.ID != id).Any(x => x.Text == model.Text))

                {
                    ModelState.AddModelError("", "Aktualność już istnieje");
                }
                Obj.Text   = model.Text;
                Obj.Header = model.Header;
                Obj.Date   = DateTime.Now;



                context.SaveChanges();
            }
            return(RedirectToAction("News"));
        }
Ejemplo n.º 4
0
        public IActionResult EditLesson(CreateLessonView model)
        {
            USOSContext context    = this.initContext();
            Lesson      editLesson = context.Lesson.Find(model.lessonID);

            if (model.lectureID != null)
            {
                editLesson.lecture = context.Lecture.Find(Convert.ToInt32(model.lectureID));
            }
            if (model.lecturerID != null)
            {
                editLesson.lecturer = _userManager.FindByNameAsync(model.lecturerID).Result;
            }
            var select = context.LessonsGroup.Where(x => x.lesson.ID == model.lessonID).Select(x => new LessonsGroup(x));

            context.LessonsGroup.RemoveRange(select);
            if (model.group != null)
            {
                foreach (int g in model.group)
                {
                    Group        group          = context.Group.Find(g);
                    LessonsGroup newLessonGroup = new LessonsGroup();
                    newLessonGroup.group  = group;
                    newLessonGroup.lesson = editLesson;
                    context.LessonsGroup.Add(newLessonGroup);
                }
            }
            context.Entry(editLesson.lecturer).State = EntityState.Unchanged;
            context.SaveChanges();
            return(RedirectToAction("Lessons", "Admin"));
        }
Ejemplo n.º 5
0
        public IActionResult EditStudentGroup(EditStudentGroup model)
        {
            USOSContext context = this.initContext();
            AppUser     student = _userManager.FindByNameAsync(model.userName).Result;
            var         select  = context.StudentGroup.Where(x => x.appUser.UserName == model.userName).Select(x => new StudentGroup()
            {
                ID = x.ID, appUser = x.appUser, group = x.group
            });

            context.StudentGroup.RemoveRange(select);

            foreach (int groupId in model.group)
            {
                Group group = context.Group.Find(groupId);
                if (group != null)
                {
                    StudentGroup newStudentGroup = new StudentGroup();
                    newStudentGroup.group   = group;
                    newStudentGroup.appUser = student;
                    context.StudentGroup.Add(newStudentGroup);
                    context.Entry(newStudentGroup.group).State   = EntityState.Unchanged;
                    context.Entry(newStudentGroup.appUser).State = EntityState.Unchanged;
                }
            }
            context.SaveChanges();

            return(RedirectToAction("Users", "Admin"));
        }
Ejemplo n.º 6
0
        public IActionResult EditLecture(Lecture model)
        {
            USOSContext context = this.initContext();

            context.Lecture.Update(model);
            context.SaveChanges();
            return(RedirectToAction("Lectures", "Admin"));
        }
Ejemplo n.º 7
0
        public IActionResult EditGroup(Group model)
        {
            USOSContext context = this.initContext();

            context.Group.Update(model);
            context.SaveChanges();
            return(RedirectToAction("Groups", "Admin"));
        }
Ejemplo n.º 8
0
 public void AddStudentToSemester(Semester semester, Student student)
 {
     _context.Add(new Semester_Student
     {
         StudentId  = student.Id,
         SemesterId = semester.Id,
         Student    = student,
         Semester   = semester,
     });
     _context.SaveChanges();
 }
Ejemplo n.º 9
0
 public void AddStudentToActivity(Activity activity, Student student)
 {
     _context.Add(new Student_Activity
     {
         StudentId  = student.Id,
         ActivityId = activity.Id,
         Student    = student,
         Activity   = activity,
     });
     _context.SaveChanges();
 }
Ejemplo n.º 10
0
        public ActionResult DeleteNews(int id)
        {
            USOSContext context = this.initContext();

            using (context)
            {
                News Obj = context.News.Find(id);
                context.News.Remove(Obj);
                context.SaveChanges();
            }

            return(RedirectToAction("News"));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> DeleteGroup(int ID)
        {
            USOSContext context = this.initContext();

            Group group = context.Group.Find(ID);

            if (group != null)
            {
                context.Group.Remove(group);
                context.SaveChanges();
            }

            return(RedirectToAction("Groups", "Admin"));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> DeleteLecture(int ID)
        {
            USOSContext context = this.initContext();


            Lecture lecture = context.Lecture.Find(ID);

            if (lecture != null)
            {
                context.Lecture.RemoveRange(lecture);
                context.Lecture.Remove(lecture);
                context.SaveChanges();
            }

            return(RedirectToAction("Lectures", "Admin"));
        }
Ejemplo n.º 13
0
        public IActionResult CreateGroup(Group model)
        {
            USOSContext context = this.initContext();

            Group newGroup = new Group();

            Group result = context.Group.Find(model.ID);

            if (result == null)
            {
                newGroup.Name = model.Name;

                context.Group.Add(newGroup);
                context.SaveChanges();
            }

            return(RedirectToAction("Groups", "Admin"));
        }
Ejemplo n.º 14
0
        public IActionResult CreateLecture(Lecture model)
        {
            USOSContext context = this.initContext();

            Lecture newLecture = new Lecture();

            Lecture result = context.Lecture.Find(model.ID);

            if (result == null)
            {
                newLecture.Name = model.Name;

                context.Lecture.Add(newLecture);
                context.SaveChanges();
            }

            return(RedirectToAction("Lectures", "Admin"));
        }
Ejemplo n.º 15
0
        public IActionResult CreateLesson(CreateLessonView lecture)
        {
            USOSContext context = this.initContext();

            Lesson newLesson = new Lesson();

            newLesson.lecture  = context.Lecture.Find(Convert.ToInt32(lecture.lectureID));
            newLesson.lecturer = _userManager.FindByNameAsync(lecture.lecturerID).Result;
            context.Lesson.Add(newLesson);
            context.Entry(newLesson.lecturer).State = EntityState.Unchanged;

            foreach (int g in lecture.group)
            {
                Group        group          = context.Group.Find(g);
                LessonsGroup newLessonGroup = new LessonsGroup();
                newLessonGroup.group  = group;
                newLessonGroup.lesson = newLesson;
                context.LessonsGroup.Add(newLessonGroup);
            }
            context.SaveChanges();
            return(RedirectToAction("Lessons", "Admin"));
        }
Ejemplo n.º 16
0
 public void Add(Teacher newTeacher)
 {
     _context.Add(newTeacher);
     _context.SaveChanges();
 }
Ejemplo n.º 17
0
 public void Add(Student newStudent)
 {
     _context.Add(newStudent);
     _context.SaveChanges();
 }
Ejemplo n.º 18
0
 public void Add(Activity newActivity)
 {
     _context.Add(newActivity);
     _context.SaveChanges();
 }
Ejemplo n.º 19
0
 public void Add(Course newCourse)
 {
     _context.Add(newCourse);
     _context.SaveChanges();
 }
Ejemplo n.º 20
0
 public void Add(Semester newSemester)
 {
     _context.Add(newSemester);
     _context.SaveChanges();
 }
Ejemplo n.º 21
0
 public void Add(Subject newSubject)
 {
     _context.Add(newSubject);
     _context.SaveChanges();
 }