public ActionResult Edit(RegistryEditView view, bool error = false) { try { ViewBag.HideScreen = false; var courses = Course.List(sort: by => by.Name); if (courses == null) { throw new Exception("Os cursos não foram listados"); } if (Equals(view.CourseSelected, Guid.Empty)) { view.CourseSelected = courses[0].IdCourse; } view.CourseSelectList = new SelectList(courses, "IdCourse", "Name", view.CourseSelected); Student logged = Student.FindLoggedUser(); if (logged == null) { throw new Exception("Aluno não encontrado"); } var list = Registry.GridList(logged.IdStudent, view.CourseSelected); if (list == null) { throw new Exception("As grades não foram listadas."); } view.Registries = Convert(view.Registries, list.ToArray()); if (error) { ViewBag.Message = "Não foi possível realizar a matrícula. Analise os erros."; } } catch (Exception e) { object[] parameters = { view, error }; string notes = LogHelper.Notes(parameters, e.Message); Log.Add(Log.TYPE_ERROR, "SistemaMatricula.Controllers.RegistryController.Edit", notes); ViewBag.Message = "Não foi possível realizar a solicitação. Erro de execução."; ViewBag.HideScreen = true; } return(View("Edit", view)); }
public ActionResult Update(RegistryEditView view) { try { if (ModelState.IsValid == false) { return(Edit(view, true)); } Student logged = Student.FindLoggedUser(); if (logged == null) { throw new Exception("Aluno não encontrado"); } foreach (RegistryView item in view.Registries) { if (item.FirstOption || item.SecondOption) { item.Student = logged; if (item.SecondOption) { item.Alternative = true; } var insert = Registry.Add(item); if (insert == false) { throw new Exception( string.Format("Matrícula não incluída. Grade: {0} Aluno: {1}", item.Grid.IdGrid, item.Student.IdStudent)); } } } return(RedirectToAction("Index", "Registry")); } catch (Exception e) { string notes = LogHelper.Notes(view, e.Message); Log.Add(Log.TYPE_ERROR, "SistemaMatricula.Controllers.RegistryController.Update", notes); ViewBag.Message = "Não foi possível realizar a solicitação. Erro de execução."; ViewBag.HideScreen = true; } return(View("Edit")); }