Exemplo n.º 1
0
        public ActionResult Create(int productId, FormCollection form)
        {
            using (var context = new LibraryContainer())
            {
                var product = context.Product.First(p => p.Id == productId);
                var comment = new Comment {Date = DateTime.Now};
                TryUpdateModel(comment, new[] {"Text"});

                var customer = context.Customer.First(c => c.Name == User.Identity.Name);
                
                comment.CustomerId = customer.Id;
                comment.CustomerName = customer.Name;
                comment.CustomerTitle = customer.Title;

                product.Comments.Add(comment);
                
                context.SaveChanges();

                return RedirectToAction("Index");
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create a new Comment object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="productId">Initial value of the ProductId property.</param>
 /// <param name="text">Initial value of the Text property.</param>
 /// <param name="date">Initial value of the Date property.</param>
 /// <param name="customerId">Initial value of the CustomerId property.</param>
 /// <param name="customerName">Initial value of the CustomerName property.</param>
 /// <param name="customerTitle">Initial value of the CustomerTitle property.</param>
 public static Comment CreateComment(global::System.Int32 id, global::System.Int32 productId, global::System.String text, global::System.DateTime date, global::System.Int32 customerId, global::System.String customerName, global::System.String customerTitle)
 {
     Comment comment = new Comment();
     comment.Id = id;
     comment.ProductId = productId;
     comment.Text = text;
     comment.Date = date;
     comment.CustomerId = customerId;
     comment.CustomerName = customerName;
     comment.CustomerTitle = customerTitle;
     return comment;
 }
Exemplo n.º 3
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);
 }