コード例 #1
0
        public RootListItem GetRootById(int id)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Roots
                    .Single(e => e.Id == id);

                var list = new List <WordListItem>();

                foreach (var item in entity.WordsList)
                {
                    var conversion = new WordListItem
                    {
                        RootId   = item.RootId,
                        RootName = item.RootName,
                        WordId   = item.WordId,
                        Notes    = item.Notes,
                        WordName = item.WordName,
                    };
                    list.Add(conversion);
                }
                return
                    (new RootListItem
                {
                    RootName = entity.RootName,
                    NotesOnRoot = entity.NotesOnRoot,
                    WordsList = list,
                });
            }
        }
コード例 #2
0
        public ActionResult Edit(int id)
        {
            var service = new WordService();
            var detail  = service.GetWordById(id);
            var model   =
                new WordListItem
            {
                WordId   = detail.WordId,
                RootId   = detail.WordId,
                WordName = detail.WordName,
                RootName = detail.RootName,
                Notes    = detail.Notes
            };

            return(View(model));
        }
コード例 #3
0
        public bool UpdateWord(WordListItem model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Words
                    .Single(e => e.WordId == model.WordId);

                entity.RootName = model.RootName;
                entity.WordName = model.WordName;
                entity.Notes    = model.Notes;
                entity.RootId   = ctx.Roots.Where(e => e.RootName == entity.RootName).Select(e => e.Id).FirstOrDefault();


                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #4
0
        public ActionResult Edit(int id, WordListItem model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.WordId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = new WordService();

            if (service.UpdateWord(model))
            {
                TempData["SaveResult"] = "Your note was updated.";
                return(RedirectToAction("Index"));
            }

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