Ejemplo n.º 1
0
        public ActionResult AddReply([Bind(Include = "TopicId,Content")] AddReplyBindingModel model)
        {
            if (this.ModelState.IsValid)
            {
                string userId = User.Identity.GetUserId();
                this.service.AddReply(model, userId);

                return(this.RedirectToAction("Detailed", new { id = model.TopicId }));
            }
            return(this.PartialView("_AddReply"));
        }
        public IActionResult Details(HttpSession session, HttpResponse response, AddReplyBindingModel arbm)
        {
            var   user  = this.data.Logins.FindByPredicate(l => l.SessionId == session.Id).User;
            var   topic = this.data.Topics.FindByPredicate(t => t.Title == arbm.TopicTitle);
            Reply reply = new Reply()
            {
                Author      = user,
                Content     = arbm.Content,
                ImageUrl    = arbm.ImageUrl,
                PublishDate = DateTime.Now
            };

            topic.Replies.Add(reply);
            this.data.SaveChanges();
            this.Redirect(response, $"/topics/details?TopicTitle={arbm.TopicTitle}");
            return(null);
        }
Ejemplo n.º 3
0
        public void AddReply(AddReplyBindingModel model, string userId)
        {
            User  currentUser  = this.GetCurrentUser(userId);
            Topic currentTopic = this.Context.Topics.Find(model.TopicId);

            if (currentTopic == null)
            {
                throw new ArgumentNullException(nameof(model.TopicId), "There is no Topic with such Id.");
            }
            Reply reply = Mapper.Instance.Map <Reply>(model);

            reply.Topic       = currentTopic;
            reply.Author      = currentUser;
            reply.PublishDate = DateTime.Now;

            this.Context.Replies.Add(reply);
            this.Context.SaveChanges();
        }