public ActionResult CreateFinal(FinalGradesViewModel gradesViewModel)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Type = "create";
                return RedirectToAction("EditFinal", new { id = gradesViewModel.grade.id_final_grade });
            }

            try
            {
                finalGradesService.Add(gradesViewModel.grade);
                TempData["Status"] = "success";
                TempData["Msg"] = "Nowa ocena została dodana!";
            }
            catch (Exception e)
            {
                TempData["Status"] = "invalid";
                TempData["Msg"] = "Nie udało się dodać nowej oceny!";
            }
            return RedirectToAction("List");
        }
        public ActionResult EditFinal(FinalGradesViewModel gradesViewModel)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Type = "edit";

                string errorString = "";

                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        errorString += error.ErrorMessage + "\n";
                    }
                }
                TempData["Status"] = "invalid";
                TempData["Msg"] = errorString;

                return RedirectToAction("EditFinal", new { id = gradesViewModel.grade.id_final_grade });
            }

            try
            {
                finalGradesService.Edit(gradesViewModel.grade);
                TempData["Status"] = "success";
                TempData["Msg"] = "Aktualizacja oceny przebiegła pomyślnie!";
            }
            catch (Exception e)
            {
                TempData["Status"] = "invalid";
                TempData["Msg"] = "Nie udało się zaktualizować oceny!";
            }
            return RedirectToAction("List");
        }
        public ActionResult EditFinal(int id)
        {
            ViewBag.Type = "edit";

            var groups = groupsService.FindAll;
            var form = creditingFormService.FindAll;
            IQueryable<Subjects> subjects = null;
            IQueryable<Users> users = null;

            if (groups != null && groups.ToList().Count() != 0)
            {
                subjects = subjectsService.FindAllSubjectsForGroup(groups.First().id_group);
                users = usersService.FindAllStudentsInGroup(groups.First().id_group);
            }

            if (id == null)
            {
                throw new FinalGradesNotFoundException();
            }

            Final_Grades grade = null;

            try
            {
                grade = finalGradesService.FindById(id);

                FinalGradesViewModel model = new FinalGradesViewModel();
                model.grade = grade;
                model.SelectedGroup = usersService.FindById(grade.id_user).id_group.ToString();
                model.SelectedSubject = grade.id_subject.ToString();
                model.SelectedUser = grade.id_user.ToString();

                ViewBag.Groups = new SelectList(groups, "id_group", "full_name");
                ViewBag.Subjects = new SelectList(subjects, "id_subject", "subject_name");
                ViewBag.Users = new SelectList(users, "id_user", "full_name");
                ViewBag.CreditingForm = new SelectList(form, "id_crediting_form", "name");

                return View("Final/Edit", model);
            }
            catch (FinalGradesNotFoundException ex)
            {
                TempData["Status"] = "invalid";
                TempData["Msg"] = "Nie znaleziono oceny!";
                return RedirectToAction("List");
            }
        }