Exemple #1
0
        public bool UpdatePrompt(PromptEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .PromptItems
                    .Single(x => x.PromptId == model.PromptId);

                entity.Prompt   = model.Prompt;
                entity.Category = model.Category;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemple #2
0
        public ActionResult Edit(int id)
        {
            var service = new PromptServices();

            var prompt = service.GetPromptById(id);

            var model =
                new PromptEdit
            {
                PromptId = prompt.PromptId,
                Category = prompt.Category,
                Prompt   = prompt.Prompt
            };

            return(View(model));
        }
Exemple #3
0
        public ActionResult Edit(int id, PromptEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.PromptId != id)
            {
                ModelState.AddModelError("", "Sorry, looks like we didn't find a Prompt with that Id.");
                return(View(model));
            }
            var service = new PromptServices();

            if (service.UpdatePrompt(model))
            {
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Prompt could not be updated.");
            return(View(model));
        }