// GET: Feature/Edit/5 public async Task <ActionResult> Edit(int?id) { //Ensure valid input if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //Find feature in database var feature = await _db.Features.FindAsync(id); if (feature == null) { return(HttpNotFound("Feature not found.")); } //TODO: Ensure user is allowed access to this project //Create and return base model var model = new FeatureEditViewModel() { Id = feature.Id, Description = feature.Description, Title = feature.Title, Weight = feature.Weight }; return(PartialView("_Edit", model)); }
public async Task <ActionResult> Edit(FeatureEditViewModel model) { //Ensure model is valid if (!ModelState.IsValid) { return(PartialView("_Edit", model)); } //Find feature in database var feature = await _db.Features.FindAsync(model.Id); if (feature == null) { return(HttpNotFound("Feature not found.")); } //TODO: Ensure user is allowed access to this project try { //Update database entry feature.Title = model.Title; feature.Description = model.Description; feature.Weight = model.Weight; //Store changes await _db.SaveChangesAsync(); return(Json(new { success = true })); } catch (Exception exception) { model.Error = exception.Message; return(PartialView("_Edit", model)); } }