public ActionResult Create(FormCollection collection) { var subject = collection["subject"]; var content = collection["content"]; var roomId = int.Parse(collection["room_id"]); var creator = Session["User"] as DAO.user; // FIXME: It would have been nicer if we could create both the // topic and the associated message in one transaction. var newTopic = new message_thread { title = subject, creator_id = (Session["User"] as user).id, room_id = roomId, created_at = DateTime.Now }; db.message_threads.InsertOnSubmit(newTopic); db.SubmitChanges(); var newMessage = new message_table { content = content, thread_id = newTopic.id, creator_id = creator.id, created_at = DateTime.Now }; var notifications = newTopic.room.moderations.Select(m => { return new DAO.notification { user_id = m.user_id, content = String.Format( "{0} has created a new topic in {1}.", creator.full_name, newTopic.room.name), url = Url.Action("Details", "Topic", new { id = newTopic.id }), created_at = DateTime.Now }; }); db.message_tables.InsertOnSubmit(newMessage); db.notifications.InsertAllOnSubmit(notifications); db.SubmitChanges(); return RedirectToAction("Details", new { id = newTopic.id }); }
private void detach_message_tables(message_table entity) { this.SendPropertyChanging(); entity.message_thread = null; }
partial void Deletemessage_table(message_table instance);
partial void Updatemessage_table(message_table instance);
partial void Insertmessage_table(message_table instance);
private void attach_message_tables(message_table entity) { this.SendPropertyChanging(); entity.user = this; }