public void InjectTags(string theme) { TchillrDBContext context = new TchillrDBContext("Server=tcp:myuc6ta27d.database.windows.net,1433;Database=TchillrDB;User ID=TchillrSGBD@myuc6ta27d;Password=Tch1llrInTown;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"); Tag tg = new Tag(); tg.Title = "Concert"; tg.Weight = 1; tg.ThemeID = 1; context.Tags.Add(tg); tg = new Tag(); tg.Title = "Festival"; tg.Weight = 1; tg.ThemeID = 1; context.Tags.Add(tg); tg = new Tag(); tg.Title = "Jazz"; tg.Weight = 1; tg.ThemeID = 1; context.Tags.Add(tg); tg = new Tag(); tg.Title = "Classique"; tg.Weight = 1; tg.ThemeID = 1; context.Tags.Add(tg); tg = new Tag(); tg.Title = "Percussion"; tg.Weight = 1; tg.ThemeID = 1; context.Tags.Add(tg); tg = new Tag(); tg.Title = "Hip Hop"; tg.Weight = 1; tg.ThemeID = 1; context.Tags.Add(tg); context.SaveChanges(); }
public List <int> PostInterests(string usernameid, Stream content) { TchillrDBContext context = new TchillrDBContext("Server=tcp:myuc6ta27d.database.windows.net,1433;Database=TchillrDB;User ID=TchillrSGBD@myuc6ta27d;Password=Tch1llrInTown;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"); int userNameID = int.Parse(usernameid); // convert Stream Data to StreamReader StreamReader reader = new StreamReader(content); string result = reader.ReadToEnd(); int tagID = int.Parse(result.Split('=')[1]); UserTag ut = context.UserTags.FirstOrDefault(userTag => userTag.TagID == tagID && userTag.UserID == userNameID); if (ut == null || ut.UserID == 0) { ut = new UserTag(); ut.UserID = userNameID; ut.TagID = tagID; context.UserTags.Add(ut); } else { context.UserTags.Remove(ut); } context.SaveChanges(); //return context.UserTags.Where(userTags => userTags.UserID == userNameID).Select(x => x.TagID).ToList<int>(); return(GetInterests(usernameid)); //JObject jsonActivities = JObject.Parse(reader.ReadToEnd()); //foreach (JObject activity in jsonActivities["data"]) //{ //} //return new List<int>(); }
public List <Data.Activity> GetStaticAllActivities() { TchillrDBContext context = new TchillrDBContext("Server=tcp:myuc6ta27d.database.windows.net,1433;Database=TchillrDB;User ID=TchillrSGBD@myuc6ta27d;Password=Tch1llrInTown;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"); //List<Data.Activity> activities = new List<Data.Activity>(); try { WebRequest req = WebRequest.Create("http://" + HttpContext.Current.Request.Url.Authority + "/staticActivy3.txt"); req.Method = "GET"; HttpWebResponse resp = req.GetResponse() as HttpWebResponse; if (resp.StatusCode == HttpStatusCode.OK) { using (Stream respStream = resp.GetResponseStream()) { StreamReader reader = new StreamReader(respStream, Encoding.UTF8); JObject jsonActivities = JObject.Parse(reader.ReadToEnd()); foreach (JObject activity in jsonActivities["data"]) { int identifier = (int)activity["identifier"]; Data.Activity act = context.Activities.Include("Occurences").FirstOrDefault(acti => acti.ID == identifier); if (act == null) { act = new Activity(); act.Occurences = new List <Occurence>(); context.Activities.Add(act); } act.Nom = WebUtility.HtmlDecode(activity["name"].ToString()); act.Adresse = WebUtility.HtmlDecode(activity["adress"].ToString()); act.City = WebUtility.HtmlDecode(activity["city"] == null ? "" : activity["city"].ToString()); act.Description = StripHTML(WebUtility.HtmlDecode(activity["description"].ToString())); act.ID = (int)activity["identifier"]; act.Zipcode = activity["zipcode"].ToString(); act.ShortDescription = activity["shortDescription"].ToString(); act.Lieu = activity["place"].ToString(); float temp = 0; if (float.TryParse(activity["latitude"].ToString(), out temp)) { act.Lat = temp; } temp = 0; if (float.TryParse(activity["longitude"].ToString(), out temp)) { act.Lon = temp; } foreach (JObject occ in activity["occurences"]) { #warning convertir en start date end date // we found that some activity have multiple equal occurences if (act.Occurences.Exists(o => o.ActivityID == act.ID && o.Day == occ["jour"].ToString() && o.StartTime == occ["hour_start"].ToString() && o.EndTime == occ["hour_end"].ToString())) { continue; } Occurence occurence = new Occurence(); occurence.Day = occ["jour"].ToString(); occurence.StartTime = occ["hour_start"].ToString(); occurence.EndTime = occ["hour_end"].ToString(); occurence.ActivityID = act.ID; act.Occurences.Add(occurence); } //act.Keywords = act.GetKeywords(); // activities.Add(act); } } } } catch (Exception exp) { Data.Activity dumb = new Data.Activity(); dumb.Adresse = exp.Message; dumb.City = exp.Source; dumb.Description = "dumb desc"; dumb.ID = 1; //activities.Add(dumb); } context.SaveChanges(); return(context.Activities.ToList <Activity>()); //return activities; }