public ActionResult Edit(Score model, FormCollection collection) { theLogger.Info("POST method Edit"); if (model == null) { return(RedirectToAction("Missing", "Error", null)); } FoireMusesConnection connection = GetConnection(); try { if (model.Id == null) { if (model.TextualSource.SourceId == null) { model.TextualSource = null; } if (model.MusicalSource.SourceId == null) { model.MusicalSource = null; } model = connection.CreateScore(model, new Result <Score>()).Wait(); } else { Score current = connection.GetScore(model.Id, new Result <Score>()).Wait(); if (current == null) { return(RedirectToAction("Missing", "Error", null)); } TryUpdateModel(current); if (current.TextualSource.SourceId == null) { current.TextualSource = null; } if (current.MusicalSource.SourceId == null) { current.MusicalSource = null; } model = connection.EditScore(current, new Result <Score>()).Wait(); } } catch (Exception e) { theLogger.Error("Stacktrace:\n" + e.StackTrace); return(RedirectToAction("Problem", "Error", null)); } if (model == null) { theLogger.Error("Reason: model is null"); return(RedirectToAction("Problem", "Error", null)); } return(RedirectToAction("Details", new { scoreId = model.Id })); }