public ActionResult AcceptAnswer(Post post)
        {
            var question = _questionRepository.Questions.WithId(post.QuestionId);

            if (!question.IsOwner(UserModel.Current.UserName)) return View("InvalidOwner");

            question.MarkAsAnswer(post.Id, UserModel.Current.UserName);
            _questionRepository.SaveChanges();

            return RedirectToAction("Details", new { id = question.Id });
        }
 public static DetailsPostViewModel CreateViewModel(Post p)
 {
     var model = new DetailsPostViewModel
                     {
                         PostId = p.Id,
                         Created = p.CreatedDate.ToString(),
                         UserName = p.CreatedBy,
                         Subject = p.Subject,
                         Body = p.Body,
                         IsAnswer = p.Question.CreatedBy != p.CreatedBy,
                         IsMarkedAsAnswer = p.Accepted
                     };
     return model;
 }
 public ReplyViewModel(Question question)
 {
     OriginalQuestion = question;
     Reply = new Post {Subject = "Re: " + question.Subject};
 }
Beispiel #4
0
 public void AddReply(Post reply)
 {
     this.Posts.Add(reply);
 }
        public ActionResult Reply(Post reply, int id, ReturnUrl url)
        {
            var question = _repositories.Questions.Get().WithId(id);

            if (question == null) return View("NotFound");

            if (!_security.HasReplyAccess(question, UserModel.Current.UserName))
            {
                TempData["message"] = _security.ErrorMessage;
                return RedirectToAction("Details", new { id = id, r = url.Url });
            }

            if (this.ModelState.IsValid)
            {
                try
                {
                    reply.CreatedBy = UserModel.Current.UserName;
                    reply.CreatedDate = DateTime.Now;

                    question.AddReply(reply);

                    _repositories.Questions.SaveChanges();

                    var user = Membership.GetUser(question.CreatedBy);
                    if (user != null)
                        _emailService.SendEmailTo(user.Email,
                                                  new StandardEmail(StandardEmail.EmailTemplate.LawyerReply));

                    return RedirectToAction("Details", new { id, r = url.Url });
                }
                catch (Exception e)
                {
                    this.ModelState.AddModelError("*", e.ToString());
                }
            }

            return View(new ReplyViewModel(question));
        }
        public ActionResult MarkAsAnswer(Post post, ReturnUrl url)
        {
            var question = _repositories.Questions.Get().WithId(post.QuestionId);

            if (!_security.CanMarkAsAnswer(question, UserModel.Current.UserName))
            {
                TempData["message"] = _security.ErrorMessage;
                return RedirectToAction("Details", new { id = question.Id });
            }

            question.MarkAsAnswer(post.Id, UserModel.Current.UserName);
            _repositories.Questions.SaveChanges();

            TempData["message"] = "You have successfully marked this question as answered. The question is now closed.";

            return RedirectToAction("Details", new {id = question.Id});
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Posts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPosts(Post post)
 {
     base.AddObject("Posts", post);
 }
 /// <summary>
 /// Create a new Post object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="questionId">Initial value of the QuestionId property.</param>
 /// <param name="subject">Initial value of the Subject property.</param>
 /// <param name="body">Initial value of the Body property.</param>
 /// <param name="createdBy">Initial value of the CreatedBy property.</param>
 /// <param name="createdDate">Initial value of the CreatedDate property.</param>
 /// <param name="accepted">Initial value of the Accepted property.</param>
 public static Post CreatePost(global::System.Int32 id, global::System.Int32 questionId, global::System.String subject, global::System.String body, global::System.String createdBy, global::System.DateTime createdDate, global::System.Boolean accepted)
 {
     Post post = new Post();
     post.Id = id;
     post.QuestionId = questionId;
     post.Subject = subject;
     post.Body = body;
     post.CreatedBy = createdBy;
     post.CreatedDate = createdDate;
     post.Accepted = accepted;
     return post;
 }
        public ActionResult FollowUp(Post reply, int id)
        {
            var question = _questionRepository.Questions.WithId(id);

            if (this.ModelState.IsValid)
            {
                try
                {
                    reply.CreatedBy = UserModel.Current.UserName;
                    reply.CreatedDate = DateTime.Now;

                    question.AddReply(reply);
                    _questionRepository.SaveChanges();

                    if (!string.IsNullOrEmpty(question.TakenBy))
                    {
                        var user = Membership.GetUser(question.TakenBy);

                        if (user != null) {
                            var detailsUrl = Url.AttorneyQuestionDetailsLink(question.Id);
                            _emailService.SendEmailTo(user.Email,
                                                      new ClientReplyEmail(question.Category.CategoryName,
                                                                           question.CourtDateAsShortString,
                                                                           question.Subject, question.Body, detailsUrl));
                        }
                    }

                    return RedirectToAction("Details", new { id = id });
                }
                catch (Exception e)
                {
                    if (e.InnerException != null)
                        this.ModelState.AddModelError("*", e.InnerException.Message);
                    else
                        this.ModelState.AddModelError("*", e.Message);
                }
            }

            return View(new ReplyViewModel(question));
        }