public ActionResult Create(SubjectsViewModel subjectsViewModel)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Type = "create";
                return(View(subjectsViewModel));
            }

            try
            {
                List <Groups> groups = new List <Groups>();

                foreach (string value in subjectsViewModel.SelectedGroups.ToList())
                {
                    groups.Add(groupsService.FindById(Convert.ToInt32(value)));
                }

                Subjects subject = subjectsViewModel.subject;
                subject.id_user = Convert.ToInt32(subjectsViewModel.SelectedUser);
                subject.Groups  = groups;

                subjectService.Add(subject);
                TempData["Status"] = "success";
                TempData["Msg"]    = "Nowy przedmiot został dodany!";
            }
            catch (Exception e)
            {
                TempData["Status"] = "invalid";
                TempData["Msg"]    = "Nie udało się dodać nowego przedmiotu!";
            }
            return(RedirectToAction("List"));
        }
        public ActionResult SubjectsInGroup(int id)
        {
            try
            {
                var subjects = subjectsService.FindAllSubjectsForGroup(id);
                ViewBag.SelectedGroup = groupsService.FindById(id).full_name;

                return(View("SubjectsInGroup", subjects));
            }
            catch (GroupNotFoundException ex)
            {
                TempData["Status"] = "invalid";
                TempData["Msg"]    = "Nie odnaleziono takiej grupy!";
            }
            return(RedirectToAction("List"));
        }
Exemplo n.º 3
0
        public ActionResult MyGrades()
        {
            Users user     = usersService.FindByName(User.Identity.Name);
            int   id_group = (int)user.id_group;

            Groups groups = groupsService.FindById(id_group);
            IEnumerable <Subjects> subjects = subjectsService.FindAllSubjectsForGroup(id_group);

            List <MyGradesViewModel> viewModel = new List <MyGradesViewModel>();
            int size = 0;

            foreach (Subjects sub in subjects)
            {
                MyGradesViewModel model = new MyGradesViewModel();

                model.user    = sub.Users.full_name;
                model.subject = sub.subject_name;

                foreach (Partial_Grades partialGrade in sub.Partial_Grades)
                {
                    if (partialGrade.id_user.CompareTo(user.id_user) == 0)
                    {
                        model.partialGrades.Add(partialGrade);
                        if (model.partialGrades.Count > size)
                        {
                            size = model.partialGrades.Count;
                        }
                    }
                }

                if (model.partialGrades.Count == 0)
                {
                    model.partialGrades.Add(new Partial_Grades());
                }

                foreach (Final_Grades finalGrade in sub.Final_Grades)
                {
                    if (finalGrade.id_user.CompareTo(user.id_user) == 0)
                    {
                        model.finalGrades.Add(finalGrade);
                    }
                }

                if (model.finalGrades.Count == 0)
                {
                    model.finalGrades.Add(new Final_Grades());
                }

                viewModel.Add(model);
            }

            foreach (MyGradesViewModel mod in viewModel)
            {
                if (mod.partialGrades.Count < size)
                {
                    while (size > mod.partialGrades.Count)
                    {
                        mod.partialGrades.Add(new Partial_Grades());
                    }
                }
            }

            ViewBag.Size = size;

            return(View("MyGrades", viewModel));
        }