//Put /api/Snippet public IHttpActionResult Post(SnippetCreate snippet) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateSnippetService(); if (!service.CreateSnippet(snippet)) { return(InternalServerError()); } return(Ok()); }
public ActionResult Create(SnippetCreate model) { if (!ModelState.IsValid) { return(View(model)); } if (_snippetService.Value.CreateSnippet(model)) { TempData["SaveResult"] = "Snippet was created!"; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Sorry, your snippet could not be created. Please try again."); return(View(model)); }
public bool CreateSnippet(SnippetCreate model) { using (var ctx = new ApplicationDbContext()) { var entity = new Snippet() { OwnerId = _userId, IsStarred = model.IsStarred, Phrase = model.Phrase, Language = model.Language, Meaning = model.Meaning, CreatedUtc = DateTimeOffset.Now }; ctx.Snippets.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateSnippet(SnippetCreate model) { CreateSnippetCallCount++; return(CreateNoteReturnValue); }
public ActionResult Create() { var model = new SnippetCreate(); return(View(model)); }