public async Task<ActionResult> Edit(string noteId, string editKey) { var model = new EditNoteViewModel(); if (await model.Initialize(noteId, editKey) == false) { return HttpNotFound(); } return View(model); }
public async Task<ActionResult> Edit(string noteId, string editKey, EditNoteViewModel model) { var validationContext = new ValidationContext(); model.Validate(validationContext); if (validationContext.HasErrors) { AddModelStateError(validationContext); return View(model); } try { var updateResponse = await model.UpdateNote(noteId, editKey); if (updateResponse.IsSuccessful) { return RedirectToAction("Get", new { noteId = noteId }); } else { return new HttpStatusCodeResult(updateResponse.StatusCode); } } catch (ValidationException ve) { AddModelStateError(ve.ValidationContext); return View(model); } }