コード例 #1
0
        // GET: Questions/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            //Question question = db.Questions.Find(id);
            PostQuestion question = (from q in db.Questions
                                     join u in db.Users on q.OwnerUserID equals u.UserID
                                     where q.Id == id
                                     select new PostQuestion
            {
                Id = q.Id,
                Question = q.PostQuestion,
                OwnerUserID = q.OwnerUserID,
                OwnerUserName = u.UserName,
                HashTags = q.HashTags
            }).FirstOrDefault();

            if (question == null)
            {
                return(HttpNotFound());
            }
            return(View(question));
        }
コード例 #2
0
 public object AddQuestion(PostQuestion question)
 {
     if (question == null || string.IsNullOrEmpty(question.Author) ||
         string.IsNullOrEmpty(question.Content) || string.IsNullOrEmpty(question.Title))
     {
         return(new ReturnResult <QuestionModel>(-4, "传入参数错误!"));
     }
     return(_QuestionService.AddQuestion(question.ToModel()));
 }
コード例 #3
0
        public object SaveAndSubmitQuestion(PostQuestion question)
        {
            if (question == null || string.IsNullOrEmpty(question.Author) ||
                string.IsNullOrEmpty(question.Content) || string.IsNullOrEmpty(question.Title))
            {
                return(new ReturnResult <QuestionModel>(-4, "传入参数错误!"));
            }
            var temp = question.ToModel();

            temp.QuestionState = 1;
            return(_QuestionService.AddQuestion(temp));
        }
コード例 #4
0
        public ActionResult Edit(PostQuestion postQuestion)
        {
            if (ModelState.IsValid)
            {
                Question question = new Question();
                question.PostQuestion = postQuestion.Question;
                question.HashTags     = postQuestion.HashTags;
                question.Id           = postQuestion.Id;
                question.ModifiedDate = DateTime.Now;
                question.OwnerUserID  = postQuestion.OwnerUserID;

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