Пример #1
0
        public ActionResult Create(WordDef wordDef)
        {
            ViewBag.currentWord = wordDef.wordId;

            if (ModelState.IsValid)
            {
                var  currentUser = manager.FindById(User.Identity.GetUserId());
                Word currentWord = db.Words.First(w => w.Id == wordDef.wordId);

                if (currentWord.User.Id == currentUser.Id)
                {
                    ViewBag.redirectUrl = Url.Action("details", "words", new { id = wordDef.wordId });
                    db.WordDefs.Add(wordDef);
                    db.SaveChanges();

                    return(PartialView("_RedirectPage"));
                }

                return(HttpNotFound());
            }
            else
            {
                return(View());
            }
        }
Пример #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            WordDef wordDef = db.WordDefs.Find(id);

            db.WordDefs.Remove(wordDef);
            db.SaveChanges();

            return(Json(new { success = true }));
        }
Пример #3
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            WordDef wordDef = db.WordDefs.Find(id);

            if (wordDef == null)
            {
                return(HttpNotFound());
            }
            return(View(wordDef));
        }
Пример #4
0
        // GET: WordDefs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            WordDef wordDef = db.WordDefs.Find(id);

            if (wordDef == null)
            {
                return(HttpNotFound());
            }
            ViewBag.wordId = new SelectList(db.Words, "Id", "WContext", wordDef.wordId);
            return(View(wordDef));
        }
Пример #5
0
        // GET: WordDefs/Delete/5
        //[ChildActionOnly]
        public ActionResult Delete(int?id)
        {
            var currentUser = manager.FindById(User.Identity.GetUserId());

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            WordDef wordDef = db.WordDefs.Find(id);

            if (wordDef == null)
            {
                return(HttpNotFound());
            }

            if (wordDef.word.User != currentUser)
            {
                return(HttpNotFound());
            }

            ViewBag.wContext = wordDef.word.WordDetail.WContext;

            return(View(wordDef));
        }
Пример #6
0
        public ActionResult Edit([Bind(Include = "id,wType,wDefinition,wExample")] WordDef wordDef)
        {
            if (wordDef.wDefinition != null)
            {
                WordDef defwordFound = db.WordDefs.Find(wordDef.id);
                if (defwordFound != null)
                {
                    defwordFound.wType           = wordDef.wType;
                    defwordFound.wDefinition     = wordDef.wDefinition;
                    defwordFound.wExample        = wordDef.wExample;
                    db.Entry(defwordFound).State = EntityState.Modified;
                    db.SaveChanges();

                    return(Json(new { success = true }));
                }
                else
                {
                    return(View(wordDef));
                }
            }

            ViewBag.wordId = new SelectList(db.Words, "Id", "WContext", wordDef.wordId);
            return(View(wordDef));
        }