Ejemplo n.º 1
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.º 2
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.º 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"));
        }
Ejemplo n.º 4
0
        public IActionResult CreateLesson()
        {
            USOSContext context = this.initContext();

            CreateLessonView lesson = new CreateLessonView();

            lesson.lectures = context.Lecture.Select(x => new SelectListItem()
            {
                Value = Convert.ToString(x.ID), Text = x.Name
            }).ToList();
            lesson.groups = context.Group.Select(x => new SelectListItem()
            {
                Value = Convert.ToString(x.ID), Text = x.Name
            }).ToList();
            IList <AppUser>       lecturers = _userManager.GetUsersInRoleAsync("Lecturer").Result;
            List <SelectListItem> list      = new List <SelectListItem>();

            foreach (AppUser user in lecturers)
            {
                list.Add(new SelectListItem()
                {
                    Value = user.UserName, Text = user.UserName
                });
            }
            lesson.lecturers = list;
            return(PartialView("CreateLesson", lesson));
        }
Ejemplo n.º 5
0
        public IActionResult MarkWorker()
        {
            USOSContext context = this.initContext();
            List<Lesson> lessons = context.Lesson.Include(x => x.lecture).ToList();
            List<LessonStudentMarkView> lessonsStudentMarkView = new List<LessonStudentMarkView>();


            foreach (Lesson lesson in lessons)
            {
                List<LessonsGroup> lessonsGroup = context.LessonsGroup.Where(x => x.lesson.ID == lesson.ID).Include(x => x.group).Include(x => x.lesson).Include(x => x.lesson.lecture).ToList();//.Select(x => new LessonsGroup(x)).ToList();
                foreach (LessonsGroup lg in lessonsGroup)
                {
                    List<StudentGroup> studentgroups = context.StudentGroup.Include(x => x.appUser).Include(x => x.group).Where(x => x.group.ID == lg.group.ID).ToList();
                    foreach (StudentGroup studentgroup in studentgroups)
                    {
                        LessonStudentMarkView view = new LessonStudentMarkView();
                        if (context.LessonStudentMark.Where(x => x.Lesson.ID == lg.lesson.ID && x.Username.UserName == studentgroup.appUser.UserName).Include(x => x.Mark).Count() != 0)
                        {
                            LessonStudentMark lessonstudentmark = context.LessonStudentMark.Where(x => x.Lesson.ID == lg.lesson.ID && x.Username.UserName == studentgroup.appUser.UserName).Include(x => x.Mark).First();
                            view.Mark = lessonstudentmark.Mark.Value;   
                        }
                        view.LessonID = lesson.ID;

                        view.Username = studentgroup.appUser.UserName;
                        view.Lesson = lg.lesson.lecture.Name;
                        lessonsStudentMarkView.Add(view);
                    }

                }

            }
            return View(lessonsStudentMarkView);
        }
Ejemplo n.º 6
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.º 7
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.º 8
0
        public ActionResult News()
        {
            USOSContext     context = this.initContext();
            List <NewsView> News;

            News = context.News.ToArray().OrderBy(x => x.ID).Select(x => new NewsView(x)).ToList();
            return(View(News));
        }
Ejemplo n.º 9
0
        public IActionResult CreateLecture()
        {
            USOSContext context = this.initContext();

            Lecture lecture = new Lecture();

            return(PartialView("CreateLecture", lecture));
        }
Ejemplo n.º 10
0
        public USOSContext initContext()
        {
            DbContextOptionsBuilder<USOSContext> options = new DbContextOptionsBuilder<USOSContext>();
            options.UseSqlServer(configuration.GetConnectionString("MyConnStr"));
            var context = new USOSContext(options.Options);

            return context;
        }
Ejemplo n.º 11
0
        public IActionResult CreateGroup()
        {
            USOSContext context = this.initContext();

            Group group = new Group();

            return(PartialView("CreateGroup", group));
        }
Ejemplo n.º 12
0
        public IActionResult EditLecture(Lecture model)
        {
            USOSContext context = this.initContext();

            context.Lecture.Update(model);
            context.SaveChanges();
            return(RedirectToAction("Lectures", "Admin"));
        }
Ejemplo n.º 13
0
        public IActionResult EditLecture(int ID)
        {
            USOSContext context = this.initContext();

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

            return(PartialView("EditLecture", lecture));
        }
Ejemplo n.º 14
0
        public IActionResult EditGroup(int ID)
        {
            USOSContext context = this.initContext();

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

            return(PartialView("EditGroup", group));
        }
Ejemplo n.º 15
0
        public IActionResult EditGroup(Group model)
        {
            USOSContext context = this.initContext();

            context.Group.Update(model);
            context.SaveChanges();
            return(RedirectToAction("Groups", "Admin"));
        }
Ejemplo n.º 16
0
        public IActionResult Lectures()
        {
            USOSContext    context = this.initContext();
            List <Lecture> lectures;

            lectures = context.Lecture.ToArray().OrderBy(x => x.ID).Select(x => new Lecture()
            {
                ID = x.ID, Name = x.Name
            }).ToList();
            return(View(lectures));
        }
Ejemplo n.º 17
0
        public IActionResult Groups()
        {
            USOSContext  context = this.initContext();
            List <Group> groups;

            groups = context.Group.ToArray().OrderBy(x => x.ID).Select(x => new Group()
            {
                ID = x.ID, Name = x.Name
            }).ToList();
            return(View(groups));
        }
Ejemplo n.º 18
0
        public ActionResult EditMark(int lessonId, string username)
        {
            USOSContext context = this.initContext();

            LessonStudentMarkView edit = new LessonStudentMarkView();
            edit.LessonID = lessonId;
            edit.Username = username;
            edit.Marks = context.Mark.Select(x => new SelectListItem() { Value = Convert.ToString(x.ID), Text = x.Name }).ToList();


            return PartialView("EditMark",edit);
        }
Ejemplo n.º 19
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.º 20
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.º 21
0
        public IActionResult EditStudentGroup(string userName)
        {
            AppUser          editUser = _userManager.FindByNameAsync(userName).Result;
            USOSContext      context  = this.initContext();
            EditStudentGroup model    = new EditStudentGroup();

            model.userName = editUser.UserName;
            model.groups   = context.Group.Select(x => new SelectListItem()
            {
                Value = Convert.ToString(x.ID), Text = x.Name
            }).ToList();

            return(PartialView("EditStudentGroup", model));
        }
Ejemplo n.º 22
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.º 23
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.º 24
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.º 25
0
        public IActionResult EditLesson(int ID)
        {
            USOSContext      context    = this.initContext();
            CreateLessonView lesson     = new CreateLessonView();
            Lesson           editLesson = context.Lesson.Where(x => x.ID == ID).Include(x => x.lecture).Include(x => x.lecturer).First();

            lesson.lectures = context.Lecture.Select(x => new SelectListItem()
            {
                Value = Convert.ToString(x.ID), Text = x.Name
            }).ToList();
            lesson.groups = context.Group.Select(x => new SelectListItem()
            {
                Value = Convert.ToString(x.ID), Text = x.Name
            }).ToList();

            IList <AppUser>       lecturers = _userManager.GetUsersInRoleAsync("Lecturer").Result;
            List <SelectListItem> list      = new List <SelectListItem>();

            foreach (AppUser user in lecturers)
            {
                SelectListItem item = new SelectListItem()
                {
                    Value = user.UserName, Text = user.UserName
                };

                list.Add(item);
            }

            foreach (SelectListItem g in lesson.groups)
            {
                var select = context.LessonsGroup.Where(x => x.lesson.ID == ID && x.group.ID == Convert.ToInt32(g.Value)).Include(x => x.lesson).Include(x => x.group).Select(x => new LessonsGroup(x));

                if (select.Count() > 0)
                {
                    g.Selected = true;
                }
            }
            lesson.lecturers  = list;
            lesson.lectureID  = editLesson.lecture.ID;
            lesson.lecturerID = editLesson.lecturer.UserName;
            lesson.lessonID   = ID;
            return(PartialView("EditLesson", lesson));
        }
Ejemplo n.º 26
0
        public ActionResult EditNews(int id)
        {
            NewsView    model;
            USOSContext context = this.initContext();

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


                if (Obj == null)
                {
                    return(Content("Strona nie istnieje"));
                }

                model = new NewsView(Obj);
            }


            return(PartialView(model));
        }
Ejemplo n.º 27
0
        public IActionResult Users()
        {
            if (!User.IsInRole("Admin"))
            {
                return(RedirectToAction("Index", "Home"));
            }

            USOSContext context   = this.initContext();
            var         userRoles = new List <AdminUsersView>();
            var         userStore = new UserStore <AppUser>(context);

            foreach (var user in userStore.Users)
            {
                var r = new AdminUsersView
                {
                    Email       = user.Email,
                    PhoneNumber = user.PhoneNumber,
                    UserName    = user.UserName,
                    Role        = new List <string>()
                };
                if (_userManager.IsInRoleAsync(user, "Student").Result)
                {
                    var list = context.StudentGroup.Where(x => x.appUser == user).Include(x => x.group).ToList();
                    foreach (StudentGroup s in list)
                    {
                        r.groups += s.group.Name + " ";
                    }
                }

                var    roles   = _userManager.GetRolesAsync(user).Result;
                string roleStr = "";
                foreach (var role in roles)
                {
                    r.Role.Add(role);
                }
                userRoles.Add(r);
            }

            return(View(userRoles));
        }
Ejemplo n.º 28
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.º 29
0
        public IActionResult Lessons()
        {
            USOSContext context = this.initContext();

            List <LessonsView> lessonsView = new List <LessonsView>();

            List <Lesson> lessons = context.Lesson.Select(x => new Lesson()
            {
                ID = x.ID, lecture = x.lecture, lecturer = x.lecturer
            }).ToList();

            foreach (Lesson lesson in lessons)
            {
                LessonsView view = new LessonsView();
                view.ID           = lesson.ID;
                view.LectureID    = lesson.lecture.ID;
                view.LectureName  = lesson.lecture.Name;
                view.LecturerName = lesson.lecturer.UserName;
                List <LessonsGroup> lessonsGroup = context.LessonsGroup.Where(x => x.lesson.ID == lesson.ID).Include(x => x.group).Include(x => x.lesson).ToList();//.Select(x => new LessonsGroup(x)).ToList();
                foreach (LessonsGroup lg in lessonsGroup)
                {
                    if (view.GroupName == null)
                    {
                        view.GroupName += lg.group.Name;
                        view.GroupID    = Convert.ToString(lg.group.ID);
                    }
                    else
                    {
                        view.GroupName += "," + lg.group.Name;
                        view.GroupID    = "," + Convert.ToString(lg.group.ID);
                    }
                }
                lessonsView.Add(view);
            }
            return(View(lessonsView));
        }
Ejemplo n.º 30
0
 public UsosSemesterService(USOSContext context)
 {
     _context = context;
 }