public ActionResult Edit(Source model, FormCollection collection) { if (model == null) { return(RedirectToAction("Problem", "Error", null)); } if (!ValidateSource(model)) { ViewBag.Error = "Certains champs sont mal rempli ou incomplet, veuillez les remplirs correctements."; if (model.Id != null) { ViewBag.HeadTitle = "Edition"; } else { ViewBag.HeadTitle = "Creation"; } return(View("Edit", model)); } FoireMusesConnection connection = GetConnection(); try { //we use the same view to edit and create, so let's differentiate both if (model.Id == null) { model = connection.CreateSource(model, new Result <Source>()).Wait(); } else { //when updating, first get the current score out of the db then update with values Source current = connection.GetSource(model.Id, new Result <Source>()).Wait(); if (current == null) { return(RedirectToAction("Problem", "Error", null)); } TryUpdateModel(current); model = connection.EditSource(current, new Result <Source>()).Wait(); } } catch (Exception e) { return(RedirectToAction("Problem", "Error", null)); } if (model == null) { return(RedirectToAction("Problem", "Error", null)); } //redirect to details return(Redirect("Details?sourceId=" + model.Id)); }