Ejemplo n.º 1
0
        public ActionResult AddComment(int Id, [Bind(Include = "Content")] AddCommentBM bind)
        {
            string userName = User.Identity.Name;

            if (this.ModelState.IsValid)
            {
                service.AddCommentToProduct(Id, userName, bind);

                return(RedirectToAction("Details", new { Id = Id }));
            }
            return(View());
        }
Ejemplo n.º 2
0
        public void AddCommentToProduct(int id, string userName, AddCommentBM bind)
        {
            DeskComputers computer = Context.Items.OfType <DeskComputers>().FirstOrDefault(desk => desk.Id == id);

            Customer customer = Context.Customers.FirstOrDefault(cust => cust.User.UserName == userName);

            ApplicationUser user = Context.Users.FirstOrDefault(user1 => user1.UserName == userName);

            Comment comment = new Comment()
            {
                PersonName = user.Name,
                Date       = DateTime.Now,
                Content    = bind.Content
            };

            computer.Comments.Add(comment);
            Context.SaveChanges();
        }