예제 #1
0
        //Get: Edit
        //FlashCard/Edit
        public ActionResult Edit(int id)
        {
            var service = CreateFlashCardService();
            var detail  = service.GetFlashCardById(id);
            var model   =
                new FlashCardEdit
            {
                Word         = detail.Word,
                Definition   = detail.Definition,
                PartOfSpeech = detail.PartOfSpeech
            };

            return(View(model));
        }
예제 #2
0
        public bool UpdateFlashCard(FlashCardEdit model, string word)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .FlashCards
                    .Single(e => word == (e.Word));
                entity.Word         = model.Word;
                entity.Definition   = model.Definition;
                entity.PartOfSpeech = model.PartOfSpeech;

                return(ctx.SaveChanges() == 1);
            }
        }
예제 #3
0
        public ActionResult Edit(string word, FlashCardEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //if (model.FlashCardId != id)
            //{
            //    ModelState.AddModelError("", "Flash card not found");
            //    return View(model);
            //}

            var service = CreateFlashCardService();

            if (service.UpdateFlashCard(model, word))
            {
                TempData["SaveResult"] = "Your flash card was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your card could not be updated.");
            return(View(model));
        }