public ActionResult Create(string Data, int TopicID) { if (!ModelState.IsValid) return View(); try { Message msg = new Message(); msg.Data = Data; msg.EntryDate = DateTime.Now; msg.DeveloperID = _dataModel.Developers.Single(d => d.UserName == User.Identity.Name).DeveloperID; msg.TopicID = TopicID; _dataModel.AddToMessages(msg); _dataModel.SaveChanges(); return RedirectToAction("Index"); } catch { return RedirectToAction("Index"); } }
/// <summary> /// Create a new Message object. /// </summary> /// <param name="messageID">Initial value of the MessageID property.</param> /// <param name="data">Initial value of the Data property.</param> /// <param name="entryDate">Initial value of the EntryDate property.</param> /// <param name="developerID">Initial value of the DeveloperID property.</param> /// <param name="topicID">Initial value of the TopicID property.</param> public static Message CreateMessage(global::System.Int32 messageID, global::System.String data, global::System.DateTime entryDate, global::System.Int32 developerID, global::System.Int32 topicID) { Message message = new Message(); message.MessageID = messageID; message.Data = data; message.EntryDate = entryDate; message.DeveloperID = developerID; message.TopicID = topicID; return message; }
/// <summary> /// Deprecated Method for adding a new object to the Messages EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToMessages(Message message) { base.AddObject("Messages", message); }