public ActionResult Edit(int id) { var detail = _snippetService.Value.GetSnippetById(id); var model = new SnippetEdit { SnippetId = detail.SnippetId, Phrase = detail.Phrase, Language = detail.Language, Meaning = detail.Meaning, }; return(View(model)); }
//Put /api/Snippet public IHttpActionResult Put(SnippetEdit snippet) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateSnippetService(); if (!service.EditSnippet(snippet)) { return(InternalServerError()); } return(Ok()); }
private bool SetStarState(int snippetId, bool newState) { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new SnippetService(userId); var detail = service.GetSnippetById(snippetId); var updatedSnippet = new SnippetEdit { SnippetId = detail.SnippetId, IsStarred = newState, Phrase = detail.Phrase, Language = detail.Language, Meaning = detail.Meaning, }; return(service.EditSnippet(updatedSnippet)); }
public bool EditSnippet(SnippetEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = GetSnippetFromDatabase(ctx, model.SnippetId); if (entity == null) { return(false); } entity.IsStarred = model.IsStarred; entity.Phrase = model.Phrase; entity.Language = model.Language; entity.Meaning = model.Meaning; entity.ModifiedUtc = DateTimeOffset.UtcNow; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, SnippetEdit model) { if (model.SnippetId != id) { ModelState.AddModelError("", "Id Mismatch... Better luck next time"); return(View(model)); } if (!ModelState.IsValid) { return(View(model)); } if (_snippetService.Value.EditSnippet(model)) { TempData["SaveResult"] = "Your note was updated"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your note could not be updated."); return(View(model)); }
public bool EditSnippet(SnippetEdit model) { throw new NotImplementedException(); }