Exemplo n.º 1
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"));
        }
Exemplo 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");
 }
Exemplo n.º 3
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"));
        }
Exemplo n.º 4
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"));
        }