public int addEvent(int appid, novaevent newevent) { try { //create the meta object for this event objectmeta obj = new objectmeta(); obj.TimesViewedApp = 0; obj.TimesViewedWeb = 0; obj.ObjectID = newevent.EventID; obj.ObjectType = 1; obj.FacebookImpressions = 0; obj.FacebookRSVPs = 0; _db.novaevents.AddObject(newevent); _db.objectmetas.AddObject(obj); _db.SaveChanges(); return 1; } catch (Exception e) { return -1; } }
public ActionResult Create(FormCollection collection) { //First we need to check the collection, and see that all required fields are filled in. //try //{ appinfo app = utility.getAppInfo(defaultappid); WebClient wc = new WebClient(); string url_request; string facebookeventid = ""; //Create the app event novaevent eventToAdd = new novaevent(); eventToAdd.EventID = (eventmodel.getMaxEventID() + 1);//Convert.ToInt32(collection["EventID"]); eventToAdd.EventDesc = collection["EventDescription"]; //todo: session app id, not 4; eventToAdd.AppID = defaultappid; eventToAdd.EventName = collection["EventName"]; string eventstart; eventstart = collection["EventStartDate"] + " " + collection["EventStartTime"] + " " + collection["EventStartTimeAMPM"]; //eventToAdd.EventStart = Convert.ToDateTime(eventstart, new CultureInfo("fr-FR",false)); eventToAdd.EventStart = DateTime.ParseExact(eventstart, "dd/MM/yyyy h:m tt", null); string eventend; if (!collection["NoEndDate"].Contains("true")) { eventend = collection["EventEndDate"] + " " + collection["EventEndTime"] + " " + collection["EventEndTimeAMPM"]; //eventToAdd.EventEnd = Convert.ToDateTime(eventend); eventToAdd.EventEnd = DateTime.ParseExact(eventend, "dd/MM/yyyy h:m tt", null); } else { eventToAdd.EventEnd = eventToAdd.EventStart; } int outnum; int.TryParse(collection["NotAttending"], out outnum); eventToAdd.NotAttending = outnum; int.TryParse(collection["Attending"], out outnum); eventToAdd.Attending = outnum; eventToAdd.LastUpdated = DateTime.Now; if(collection["Disabled"].Contains("true")){ eventToAdd.Disabled = 1; } else { eventToAdd.Disabled = 0; } eventToAdd.Location = collection["EventLocation"]; //Compute SHA1 hash for the syncid, and encode it in 32bit SHA1 hash = SHA1.Create(); ASCIIEncoding encoder = new ASCIIEncoding(); byte[] bytearray = encoder.GetBytes(collection["EventID"] + "alexrocks_21"); hash.ComputeHash(bytearray); string syncid = ""; for (int i = 0; i < hash.Hash.Length; i++) { syncid = syncid + hash.Hash[i].ToString("x2"); } eventToAdd.SyncID = syncid; if (collection["EventSurvey"] != null && Convert.ToInt32(collection["EventSurvey"]) > 0) { eventToAdd.Survey = Convert.ToInt32(collection["EventSurvey"]); } //throw new Exception(); //add the new object to the database int ret = eventmodel.addEvent(defaultappid, eventToAdd); if (ret != 1) { ViewData["ReturnMessage"] = "Error, could not add event."; return View(); } ret = eventmodel.setLastEventUpdate(defaultappid, DateTime.Now); if (ret != 1) { ViewData["ReturnMessage"] = "Error, could not update last event date."; return View(); } //Create the Facebook event if (collection["PostToFacebook"].Contains("true")) { NameValueCollection nvc = new NameValueCollection(); DateTime tempdate; TimeSpan tempspan; string fbdate; CultureInfo provider = CultureInfo.InvariantCulture; string dateformat = "dd/MM/yyyy h:mmtt"; tempdate = DateTime.ParseExact(collection["FacebookEventStartDate"] + " " + collection["FacebookEventStartTime"] + collection["FacebookEventStartTimeAMPM"], dateformat, new System.Globalization.CultureInfo("en-GB")); //TODO: //Awkward hack to fix facebook times on events, ideally this would use the current timezone fbdate = Convert.ToString(tempdate.Year) + "-" + Convert.ToString(tempdate.Day) + "-" + Convert.ToString(tempdate.Month) + "T" + Convert.ToString(tempdate.Hour) + ":" + Convert.ToString(tempdate.Minute); fbdate = tempdate.ToString("yyyy-MM-ddTHH:mm:ss"); nvc.Add("start_time", fbdate); if (!collection["NoEndDate"].Contains("true")) { //tempdate = Convert.ToDateTime(collection["FacebookEventEndDate"] + " " + collection["FacebookEventEndTime"] + collection["FacebookEventEndTimeAMPM"]); tempdate = DateTime.ParseExact(collection["FacebookEventEndDate"] + " " + collection["FacebookEventEndTime"] + collection["FacebookEventEndTimeAMPM"], dateformat, new System.Globalization.CultureInfo("en-GB")); fbdate = tempdate.ToString("yyyy-MM-ddTHH:mm:ss"); nvc.Add("end_time", fbdate); } nvc.Add("access_token", app.FacebookPageAccessToken); nvc.Add("name", collection["FacebookEventName"]); nvc.Add("description", collection["FacebookEventDescription"]); nvc.Add("location", collection["FacebookEventLocation"]); byte[] result = wc.UploadValues("https://graph.facebook.com/" + app.FacebookPageId + "/events", "POST", nvc); string strresult = Encoding.Default.GetString(result); JObject eventresponse = JObject.Parse(strresult); if(eventresponse["id"] != null){ facebookeventid = (string)eventresponse["id"]; } } //Create the twitter message 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") && facebookeventid != "") { tweettext = tweettext + " http://facebook.com/events/" + facebookeventid; } TwitterResponse<TwitterStatus> resp = TwitterStatus.Update(at, tweettext); } ViewData["ReturnMessage"] = "Event created!"; return RedirectToAction("Home"); //} //catch(Exception e) //{ // ViewData["ReturnMessage"] = "Error, could not create event from form data <br /> Exception: " + e.Message + "<br /> Source: " + e.StackTrace ; // ViewData["ReturnMessage"] += " <br /> Event start collections: " + collection["EventStartDate"] + " " + collection["EventStartTime"] + collection["EventStartTimeAMPM"]; // return View(); //} }
public ActionResult Edit(int id, FormCollection collection) { try { novaevent selectedEvent = eventmodel.getEvent(id); novaevent updatedEvent = new novaevent(); updatedEvent = selectedEvent; updatedEvent.EventDesc = collection["EventDescription"]; updatedEvent.EventName = collection["EventName"]; string eventstart; eventstart = collection["EventStartDate"] + " " + collection["EventStartTime"] + " " + collection["EventStartTimeAMPM"]; //eventToAdd.EventStart = Convert.ToDateTime(eventstart, new CultureInfo("fr-FR",false)); updatedEvent.EventStart = DateTime.ParseExact(eventstart, "dd/M/yyyy h:mm tt", null); string eventend; if (!collection["NoEndDate"].Contains("true")) { eventend = collection["EventEndDate"] + " " + collection["EventEndTime"] + " " + collection["EventEndTimeAMPM"]; //eventToAdd.EventEnd = Convert.ToDateTime(eventend); updatedEvent.EventEnd = DateTime.ParseExact(eventend, "dd/M/yyyy h:mm tt", null); } else { updatedEvent.EventEnd = updatedEvent.EventStart; } //updatedEvent.EventStart = Convert.ToDateTime(collection["EventStart"]); //updatedEvent.EventEnd = Convert.ToDateTime(collection["EventEnd"]); updatedEvent.NotAttending = Convert.ToInt32(collection["NotAttending"]); updatedEvent.Attending = Convert.ToInt32(collection["Attending"]); updatedEvent.LastUpdated = DateTime.Now; updatedEvent.Location = collection["EventLocation"]; //add the new object to the database int ret = eventmodel.updateEvent(defaultappid, updatedEvent); if (ret != 1) { ViewData["ReturnMessage"] = "Error, could not add event."; return View(); } ret = eventmodel.setLastEventUpdate(defaultappid, DateTime.Now); if (ret != 1) { ViewData["ReturnMessage"] = "Error, could not update last event date."; return View(); } //return RedirectToRoute(new System.Web.Routing.RouteValueDictionary(new { controller = "Events", action = "Details", id = id })); return Redirect("../Events/Details?id=" + Convert.ToString(id)); } catch { ViewData["ReturnMessage"] = "Error, could not create event from form data"; return View(); } }
public int updateEvent(int appid, novaevent updatedevent) { try { var selected_event = (from e in _db.novaevents where (e.AppID == appid && e.EventID == updatedevent.EventID) select e).First(); selected_event = updatedevent; _db.novaevents.ApplyCurrentValues(selected_event); _db.SaveChanges(); return 1; } catch (Exception e) { return -1; } }
/// <summary> /// Deprecated Method for adding a new object to the novaevents EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddTonovaevents(novaevent novaevent) { base.AddObject("novaevents", novaevent); }
/// <summary> /// Create a new novaevent object. /// </summary> /// <param name="eventID">Initial value of the EventID property.</param> /// <param name="syncID">Initial value of the SyncID property.</param> /// <param name="appID">Initial value of the AppID property.</param> /// <param name="eventName">Initial value of the EventName property.</param> /// <param name="eventDesc">Initial value of the EventDesc property.</param> /// <param name="eventStart">Initial value of the EventStart property.</param> /// <param name="attending">Initial value of the Attending property.</param> /// <param name="notAttending">Initial value of the NotAttending property.</param> /// <param name="lastUpdated">Initial value of the LastUpdated property.</param> /// <param name="eventEnd">Initial value of the EventEnd property.</param> /// <param name="disabled">Initial value of the Disabled property.</param> public static novaevent Createnovaevent(global::System.Int32 eventID, global::System.String syncID, global::System.Int32 appID, global::System.String eventName, global::System.String eventDesc, global::System.DateTime eventStart, global::System.Int32 attending, global::System.Int32 notAttending, global::System.DateTime lastUpdated, global::System.DateTime eventEnd, global::System.Int32 disabled) { novaevent novaevent = new novaevent(); novaevent.EventID = eventID; novaevent.SyncID = syncID; novaevent.AppID = appID; novaevent.EventName = eventName; novaevent.EventDesc = eventDesc; novaevent.EventStart = eventStart; novaevent.Attending = attending; novaevent.NotAttending = notAttending; novaevent.LastUpdated = lastUpdated; novaevent.EventEnd = eventEnd; novaevent.Disabled = disabled; return novaevent; }