//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());
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 4
0
        public bool CreateSnippet(SnippetCreate model)
        {
            CreateSnippetCallCount++;

            return(CreateNoteReturnValue);
        }
Esempio n. 5
0
        public ActionResult Create()
        {
            var model = new SnippetCreate();

            return(View(model));
        }