public string SearchMood(SearchString searchString) { try { using (var context = new QuotesDB()) { List <UserQuote> getAllQuotesForMood = context.Quotes.Where(c => c.Emotion.ToLower().Contains(searchString.searchString.ToLower())).ToList(); return(new JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(getAllQuotesForMood)); } } catch (Exception ex) { return("An error has occured, please contact the site administrator."); } }
public ActionResult MultiThreading() { try { using (var context = new QuotesDB()) { List <UserQuote> getAllQuotes = context.Quotes.ToList(); foreach (UserQuote userQuote in getAllQuotes) { Thread workerThread = new Thread(() => SomeDelegate(userQuote)); workerThread.Start(); } TempData["TransformedQuotes"] = transformedStrings; return(View()); } } catch (Exception ex) { TempData["TransformedQuotes"] = null; return(View()); } }
public string QuotesPerMood() { try { using (var context = new QuotesDB()) { Dictionary <string, int> moodNumber = new Dictionary <string, int>(); List <UserQuote> getAllQuotes = context.Quotes.ToList(); List <string> getMoods = context.Quotes.Select(c => c.Emotion).Distinct().ToList(); foreach (string mood in getMoods) { int count = context.Quotes.Where(c => c.Emotion == mood).Count(); moodNumber.Add(mood, count); } return(new JavaScriptSerializer { MaxJsonLength = Int32.MaxValue }.Serialize(moodNumber)); } } catch (Exception ex) { return("An error has occured, please contact the site administrator."); } }
public RedirectToRouteResult AddQuote(string quote, string author, string emotion, string source) { try { using (var context = new QuotesDB()) { UserQuote addQuote = new UserQuote(); addQuote.Quote = quote; addQuote.Author = author; addQuote.Emotion = emotion; addQuote.Source = source; addQuote.TransformedQuote = addQuote.ToString(); addQuote.DateCreated = DateTime.Now; context.Quotes.Add(addQuote); context.SaveChanges(); OAuthTokens accesstoken = new OAuthTokens() { AccessToken = "1168437102-OPhanbNtRtHHlCmRHiEhduDGtJuhnd7iiMVnImW", AccessTokenSecret = "Z0oya1CYE2hion4GS1VTEYq2xSuxqkqC8vbyLAPQpfjbg", ConsumerKey = "EqmTjW9ILHdBtNJyob8WpqFKr", ConsumerSecret = "J6zUucZk33nwvrWHsD7v0AcFaN7NqRlSsZHmfazXk3NkoKfzc2" }; TwitterResponse <TwitterStatus> response = TwitterStatus.Update( accesstoken, quote); TempData["Result"] = "Your quote has been added to the database."; return(this.RedirectToAction("Index")); } } catch (Exception ex) { TempData["Result"] = "An error has occured, please contact the system administrator."; return(this.RedirectToAction("Index")); } }
public AddQuote(QuotesDB.Sqlite db) { this.db = db; InitializeComponent(); }