示例#1
0
        public ActionResult Create(Topic topic)
        {
            User user = db.Users.FirstOrDefault();

            if (user != null)
                topic.CreatedById = user.UserId;
            else
                ModelState.AddModelError(string.Empty, "User is wrong");

            if (ModelState.IsValid)
            {
                db.Topics.Add(topic);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(topic);
        }
示例#2
0
        public ActionResult Edit(Topic topic)
        {
            if (ModelState.IsValid)
            {
                var edited = db.Topics.Find(topic.TopicId);

                edited.Title = topic.Title;
                edited.Content = topic.Content;

                db.Entry(edited).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(topic);
        }