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

            if (model.MeaningId != id)
            {
                ModelState.AddModelError("", "Word is null");
                return(View(model));
            }

            var service = new MeaningService();



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

            ModelState.AddModelError("", "Your meaning could not be updated.");
            return(View(model));
        }
コード例 #2
0
        public ActionResult EditMeaning(MeaningListItem oldMeaning)
        {
            var service = new MeaningService();
            var update  = service.UpdateMeaning(oldMeaning);

            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public bool UpdateMeaning(MeaningListItem model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Meanings
                    .Single(e => e.MeaningId == model.MeaningId);

                entity.MeaningId       = model.MeaningId;
                entity.WordName        = model.WordName;
                entity.Context         = model.Context;
                entity.Description     = model.Description;
                entity.RegionalDialect = model.RegionalDialect;
                entity.DialectList     = model.DialectList;
                //entity.CumulativeRating = model.CumulativeRating;


                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #4
0
        public WordDetail GetWordById(int id)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Words
                    .Single(e => e.WordId == id);

                var list = new List <MeaningListItem>();

                foreach (var item in entity.Meanings)
                {//Converting meanings into meaninglistitems
                    var conversion = new MeaningListItem
                    {
                        MeaningId        = item.MeaningId,
                        WordName         = item.WordName,
                        Pronunciation    = item.Pronunciation,
                        Context          = item.Context,
                        Description      = item.Description,
                        RegionalDialect  = item.RegionalDialect,
                        DialectList      = item.DialectList,
                        WordId           = item.WordId,
                        CumulativeRating = item.CumulativeRating,
                    };
                    list.Add(conversion);
                }

                return
                    (new WordDetail
                {
                    WordId = entity.WordId,
                    Notes = entity.Notes,
                    WordName = entity.WordName,
                    RootName = entity.RootName,
                    Meanings = list,
                });
            }
        }