public ActionResult EditPartial(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 PartialGradesNotFoundException(); } Partial_Grades grade = null; try { grade = partialGradesService.FindById(id); PartialGradesViewModel model = new PartialGradesViewModel(); 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("Partial/Edit",model); } catch (PartialGradesNotFoundException ex) { TempData["Status"] = "invalid"; TempData["Msg"] = "Nie znaleziono oceny!"; return RedirectToAction("List"); } }
public ActionResult EditPartial(PartialGradesViewModel 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("EditPartial", new { id = gradesViewModel.grade.id_grade }); } try { partialGradesService.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 CreatePartial(PartialGradesViewModel gradesViewModel) { if (!ModelState.IsValid) { ViewBag.Type = "create"; return RedirectToAction("CreatePartial"); } try { partialGradesService.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"); }