public ActionResult Edit(MultimediaTypeViewMode viewModel) { // Sprawdź status modelu if (ModelState.IsValid) { try { // Zapisz obiekt do repozytorium var response = _repository.Save(viewModel.MultimediaType); if (response != null && !response.Accepted) { foreach (var r in response.Errors) { var key = string.IsNullOrEmpty(r.Property) ? "" : ("MultimediaType." + r.Property); ModelState.AddModelError(key, r.Message); } return(View(viewModel)); } } catch (Exception ex) { // Obsłuż błędy DbValidationErrorHandler.ModelHandleException(ex, ModelState, "MultimediaType"); return(View(viewModel)); } return(RedirectToAction("Index", "Default", new { ctr = "MultimediaTypes" })); } else { return(View(viewModel)); } }
public ActionResult Edit(CampaignPriorityViewModel viewModel) { // Sprawdzenie stanu modelu if (ModelState.IsValid) { try { // Zapis obiektu do repozytorium var response = _repository.Save(viewModel.Priority); if (response != null && !response.Accepted) { foreach (var r in response.Errors) { var key = string.IsNullOrEmpty(r.Property) ? "" : ("Priority." + r.Property); ModelState.AddModelError(key, r.Message); } return(View(viewModel)); } } catch (Exception ex) { // Obsługa błędów DbValidationErrorHandler.ModelHandleException(ex, ModelState, "Priority"); return(View(viewModel)); } return(RedirectToAction("Index", "Default", new { ctr = "CampaignPriorities" })); } // Niepoprawne dane - zwróc formularz użytkownikowi Error("Niepoprawne dane"); return(View(viewModel)); }
/// <summary> /// Zebranie informacji do zalgowania /// </summary> /// <param name="ex">Wyjątek</param> /// <param name="logPath">Ścieżka do katalogu logów</param> /// <param name="filterContext">Kontekst wyjątku</param> /// <param name="primaryMessage">Główny komunikat błędu</param> private string LogException(Exception ex, string logPath, ExceptionContext filterContext, out string primaryMessage) { List <Exception> hierarchy = new List <Exception>(); primaryMessage = string.Empty; ///Obsługa błędów bazodanowych if (ex is System.Data.Entity.Validation.DbEntityValidationException) { ///Pobranie informacji o błędach EF using (DbValidationErrorHandler dbValExp = new DbValidationErrorHandler(ex as System.Data.Entity.Validation.DbEntityValidationException)) { if (dbValExp.HasErrors) { foreach (var exp in dbValExp.ValidationErrors) { hierarchy.Add(new Exception(exp.Message)); } primaryMessage = string.Join(Environment.NewLine, dbValExp.ValidationErrors.Select(s => s.Message).ToArray()); } else { primaryMessage = ex.Message; ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy); } } } ///Obsługa zwykłych błędów else { primaryMessage = ex.Message; ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy); } string destinationPath = logPath; return(LogToFile(ref hierarchy, destinationPath, null, filterContext)); }