コード例 #1
0
        // GET: Edit
        public ActionResult Edit(int?wordId, int?id)
        {
            if (wordId is null || id is null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var service  = CreateSentenceService((int)wordId);
            var sentence = service.GetSentenceById((int)id);

            if (sentence is null)
            {
                return(HttpNotFound());
            }

            var model =
                new SentenceEdit
            {
                SentenceId          = (int)id,
                SentenceContent     = sentence.SentenceContent,
                SentenceTranslation = sentence.SentenceTranslation
            };

            ViewData["WordId"] = (int)wordId;
            return(View(model));
        }
コード例 #2
0
        // Update
        public bool UpdateSentence(SentenceEdit model)
        {
            var entity =
                _context
                .Sentences
                .SingleOrDefault(e => e.UserId == _userId && e.SentenceId == model.SentenceId);

            entity.SentenceContent     = model.SentenceContent;
            entity.SentenceTranslation = model.SentenceTranslation;

            return(_context.SaveChanges() == 1);
        }
コード例 #3
0
        public ActionResult Edit(int languageId, int wordId, int id, SentenceEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateSentenceService(wordId);

            if (service.UpdateSentence(model))
            {
                TempData["SaveResult"] = "Sentence was successfully updated.";
                return(RedirectToAction("Details", "Word", new { languageId, id = wordId }));
            }

            ModelState.AddModelError("", "Sentence was not updated.");
            return(View(model));
        }