Esempio n. 1
0
        // GET: StudentActivities/ListActivities/5
        public ActionResult StudentListActivities(int?id)
        {
            var user = (from u in db.Users
                        where u.UserName == User.Identity.Name
                        select u).FirstOrDefault();

            if (user == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var activities = (from a in db.StudentActivities
                              where a.StudentId == user.Id
                              select a).ToList();

            if (activities == null)
            {
                return(HttpNotFound());
            }

            var studentActivities = new List <StudentActivityViewModel>();

            foreach (var activity in activities)
            {
                var sa  = new StudentActivityViewModel();
                var act = (from ac in db.Activities
                           where ac.ModuleId == id && ac.Id == activity.ActivityId
                           select ac).ToList();

                if (act.Count() == 0)
                {
                    continue;
                }

                var a = act.First();

                sa.Id           = activity.Id;
                sa.ActivityName = a.Name;
                sa.Status       = activity.Status;
                sa.Grade        = activity.Grade;
                sa.Documents    = a.Documents.ToList();
                sa.Homeworks    = activity.Documents.ToList();

                studentActivities.Add(sa);
            }

            var module = (from m in db.Modules
                          where m.Id == id
                          select m).First();

            ViewBag.id                = id;
            ViewBag.moduleName        = module.Name;
            ViewBag.moduleDescription = module.Description;
            ViewBag.Documents         = module.Documents.ToList();

            return(View(studentActivities));
        }
Esempio n. 2
0
        //public ActionResult ManageHomeworkFiles(Document.DocumentTypes documentType, int objectId, string returnAction, string returnController)
        //{
        //    Document document = db.Documents.Find(objectId);

        //    return View(document);
        //}

        public ActionResult ManageHomeworkFiles(int id)
        {
            var user = (from u in db.Users
                        where u.UserName == User.Identity.Name
                        select u).FirstOrDefault();

            if (user == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var activities = (from a in db.StudentActivities
                              where a.StudentId == user.Id
                              select a).Where(a => a.Id == id).ToList();

            if (activities == null)
            {
                return(HttpNotFound());
            }

            var studentActivities = new List <StudentActivityViewModel>();

            foreach (var activity in activities)
            {
                var sa = new StudentActivityViewModel();
                var a  = (from ac in db.Activities
                          where ac.Id == activity.ActivityId
                          select ac).First();

                sa.Id           = activity.Id;
                sa.ActivityName = a.Name;
                sa.Status       = activity.Status;
                sa.Grade        = activity.Grade;
                sa.Documents    = a.Documents.ToList();
                sa.Homeworks    = activity.Documents.ToList();

                studentActivities.Add(sa);
            }

            var sact = studentActivities.FirstOrDefault();

            ViewBag.id           = sact.Id;
            ViewBag.activityName = sact.ActivityName;
            ViewBag.status       = sact.Status;
            ViewBag.grade        = sact.Grade;

            return(View(studentActivities));
        }
Esempio n. 3
0
        public ActionResult EditStudent(StudentActivityViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var studentActivity = (from sa in db.StudentActivities
                                       where sa.StudentId == viewModel.StudentId && sa.ActivityId == viewModel.ActivityId
                                       select sa).First();

                studentActivity.Status = viewModel.Status;
                studentActivity.Grade  = viewModel.Grade;

                db.Entry(studentActivity).State = EntityState.Modified;
                db.SaveChanges();

                LMS.Shared.Database.UpdateUsers(db);

                return(RedirectToAction("HandleClass", new { Id = studentActivity.ActivityId }));
            }

            return(View(viewModel));
        }
Esempio n. 4
0
        // GET: StudentActivities/EditStudent/5
        public ActionResult EditStudent(int activityId, string studentId)
        {
            if (activityId == 0 || string.IsNullOrEmpty(studentId))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var user = (from u in db.Users
                        where u.Id == studentId
                        select u).FirstOrDefault();

            if (user == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var studentActivity = (from a in db.StudentActivities
                                   where a.StudentId == user.Id && a.ActivityId == activityId
                                   select a).First();

            if (studentActivity == null)
            {
                return(HttpNotFound());
            }

            var activityName = (from a in db.Activities
                                where a.Id == activityId
                                select a.Name).First();

            var viewModel = new StudentActivityViewModel {
                ActivityId = activityId, ActivityName = activityName,
                StudentId  = user.Id, StudentName = user.FullName,
                Status     = studentActivity.Status, Grade = studentActivity.Grade
            };

            return(View(viewModel));
        }
Esempio n. 5
0
        public async Task <IActionResult> Protect(int?id, string ReturnUrl, int?groupId)
        {
            if (id == null || !ActivityExists((int)id))
            {
                return(NotFound());
            }

            if (User.IsInRole("student"))
            {
                User user = await _userManager.FindByNameAsync(User.Identity.Name);

                var student = await _context.Students.FindAsync(user.SubjectAreaId);

                var activityProtect = await _context.Activities
                                      .Include(x => x.SemesterDiscipline)
                                      .ThenInclude(x => x.Discipline)
                                      .ThenInclude(x => x.GroupDiscipline)
                                      .Include(x => x.ActivityProtections.Where(x => x.StudentId == user.SubjectAreaId))
                                      .Include(x => x.Type)
                                      .Where(x => x.Id == id && x.SemesterDiscipline.Discipline.GroupDiscipline.Any(x => x.GroupId == student.GroupId))
                                      .FirstOrDefaultAsync();

                if (activityProtect == null)
                {
                    return(Redirect("/Account/AccessDenied"));
                }

                return(View("ProtectResult", activityProtect));
            }

            var activity = await _context.Activities
                           .Include(a => a.SemesterDiscipline)
                           .ThenInclude(b => b.Discipline)
                           .ThenInclude(b => b.GroupDiscipline)
                           .Include(a => a.Type)
                           .FirstOrDefaultAsync(m => m.Id == id);

            var groups = _context.AcademicGroups
                         .Include(x => x.GroupDiscipline)
                         .Where(x => x.GroupDiscipline.Any(y => y.DisciplineId == activity.SemesterDiscipline.DisciplineId))
                         .AsNoTracking().ToList();

            ViewData["Groups"] = new SelectList(groups, "Id", "Name", groupId);

            if (groupId != null)
            {
                groups = groups.Where(x => x.Id == groupId).ToList();
            }

            var students = _context.Students
                           .Include(x => x.ActivityProtections.Where(y => y.ActivityId == id).OrderByDescending(y => y.ProtectionDate))
                           .Include(x => x.Group)
                           .OrderBy(x => x.Group.Name)
                           .ThenBy(x => x.FullName)
                           .Where(x => groups.Contains(x.Group))
                           .AsNoTracking()
                           .ToList();

            var activityProtections = new StudentActivityViewModel()
            {
                Activity = activity, Students = students
            };

            ViewData["groupId"]   = groupId;
            ViewData["ReturnUrl"] = ReturnUrl;
            return(View(activityProtections));
        }