public int addMessage(int appid, message newmessage) { newmessage.AppID = appid; try { objectmeta obj = new objectmeta(); obj.TimesViewedApp = 0; obj.TimesViewedWeb = 0; obj.ObjectID = newmessage.MessageID; obj.ObjectType = 2; obj.FacebookImpressions = 0; obj.FacebookRSVPs = 0; _db.messages.AddObject(newmessage); _db.objectmetas.AddObject(obj); _db.SaveChanges(); return 1; } catch (Exception e) { return -1; } }
/// <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); }
public ActionResult Create(FormCollection collection) { WebClient wc = new WebClient(); string facebookpostid = ""; appinfo app = utility.getAppInfo(defaultappid); try { message newmessage = new message { MessageContents = collection["MessageContents"], MessageTitle = collection["MessageTitle"], MessageDate = DateTime.Now, MessageID = (messagesmodel.getMaxMessageID() + 1),//Convert.ToInt32(collection["MessageID"]), AppID = defaultappid }; int ret = messagesmodel.addMessage(defaultappid, newmessage); if (ret != 1) { return View(); } ret = messagesmodel.setLastMessageUpdate(defaultappid, DateTime.Now); //create the facebook wall post if (collection["PostToFacebook"].Contains("true")) { NameValueCollection nvc = new NameValueCollection(); nvc.Add("access_token", app.FacebookPageAccessToken); nvc.Add("message", collection["FacebookWallPost"]); byte[] result = wc.UploadValues("https://graph.facebook.com/" + app.FacebookPageId + "/feed", "POST", nvc); string strresult = Encoding.Default.GetString(result); JObject wallresponse = JObject.Parse(strresult); if (wallresponse["id"] != null) { facebookpostid = (string)wallresponse["id"]; } } //create the tweet if (collection["PostToTwitter"].Contains("true")) { OAuthTokens at = new OAuthTokens(); at.AccessToken = app.TwitterAccessToken; at.AccessTokenSecret = app.TwitterAccessTokenSecret; at.ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"]; at.ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"]; string tweettext = ""; tweettext = collection["TweetText"]; if (collection["TwitterEventLink"].Contains("true") && facebookpostid != "") { tweettext = tweettext + " http://facebook.com/" + app.FacebookPageId; } TwitterResponse<TwitterStatus> resp = TwitterStatus.Update(at, tweettext); } return RedirectToAction("Home"); } catch(Exception e) { return View(); } }
/// <summary> /// Create a new message object. /// </summary> /// <param name="messageID">Initial value of the MessageID property.</param> /// <param name="appID">Initial value of the AppID property.</param> /// <param name="messageTitle">Initial value of the MessageTitle property.</param> /// <param name="messageContents">Initial value of the MessageContents property.</param> /// <param name="messageDate">Initial value of the MessageDate property.</param> public static message Createmessage(global::System.Int32 messageID, global::System.Int32 appID, global::System.String messageTitle, global::System.String messageContents, global::System.DateTime messageDate) { message message = new message(); message.MessageID = messageID; message.AppID = appID; message.MessageTitle = messageTitle; message.MessageContents = messageContents; message.MessageDate = messageDate; return message; }