Beispiel #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);
        }