Exemplo n.º 1
0
        public PartialViewResult AddComment(CommentFormModel commentFormModel)
        {
            if (ModelState.IsValid)
            {
                using (var context = new ShopContainer())
                {
                    try
                    {
                        Comment comment = new Comment
                                              {
                                                  Date = DateTime.Now,
                                                  Email = commentFormModel.Email,
                                                  IsAdmin = false,
                                                  Name = commentFormModel.Name,
                                                  Phone = commentFormModel.Phone,
                                                  Title = commentFormModel.Title,
                                                  Text = commentFormModel.Text
                                              };

                        context.AddToComment(comment);
                        context.SaveChanges();
                        return PartialView("_Comment", comment);
                    }
                    catch (Exception)
                    {
                        return PartialView("_CommentForm", commentFormModel);
                    }
                }
            }
            return PartialView("_CommentForm", commentFormModel);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Comment EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToComment(Comment comment)
 {
     base.AddObject("Comment", comment);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Create a new Comment object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="date">Initial value of the Date property.</param>
 /// <param name="text">Initial value of the Text property.</param>
 /// <param name="isAdmin">Initial value of the IsAdmin property.</param>
 public static Comment CreateComment(global::System.Int32 id, global::System.String name, global::System.DateTime date, global::System.String text, global::System.Boolean isAdmin)
 {
     Comment comment = new Comment();
     comment.Id = id;
     comment.Name = name;
     comment.Date = date;
     comment.Text = text;
     comment.IsAdmin = isAdmin;
     return comment;
 }