From 0add14850adff48d3421d2527d8e40b18b606131 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 30 May 2017 17:34:15 -0400 Subject: [PATCH] Quotes backend, sorta. --- Project-Unite/Controllers/APIController.cs | 24 +++++++++++++++++++++- Project-Unite/Models/IdentityModels.cs | 10 +++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Project-Unite/Controllers/APIController.cs b/Project-Unite/Controllers/APIController.cs index f225c68..925fb90 100644 --- a/Project-Unite/Controllers/APIController.cs +++ b/Project-Unite/Controllers/APIController.cs @@ -12,6 +12,28 @@ namespace Project_Unite.Controllers { public class APIController : Controller { + public ActionResult GetRandomQuote() + { + var db = new ApplicationDbContext(); + var quotes = db.Quotes.ToArray(); + if (quotes.Length == 0) + { + return Content(Serializer.Serialize(new Quote + { + Id = "DEADDEAD", + AuthorAvatar = "", + AuthorId = "No data.", + Body = "There is no quote data on http://getshiftos.ml/. Please submit some quotes!", + Year = 8675309 + })); + } + else + { + var rnd = new Random(); + return Content(Serializer.Serialize(quotes[rnd.Next(0, quotes.Length)])); + } + } + public ActionResult GetPongCP() { try @@ -103,7 +125,7 @@ public ActionResult GetCodepoints() } } - public ActionResult SetCodepoints(long id) + public ActionResult SetCodepoints(ulong id) { try { diff --git a/Project-Unite/Models/IdentityModels.cs b/Project-Unite/Models/IdentityModels.cs index 1b87197..86de44d 100644 --- a/Project-Unite/Models/IdentityModels.cs +++ b/Project-Unite/Models/IdentityModels.cs @@ -225,6 +225,15 @@ public UserFollow[] Followers } } + public class Quote + { + public string Id { get; set; } + public string AuthorId { get; set; } + public string Body { get; set; } + public string AuthorAvatar { get; set; } + public long Year { get; set; } + } + public class BannedIP { public string Id { get; set; } @@ -254,6 +263,7 @@ public static ApplicationDbContext Create() return new ApplicationDbContext(); } + public DbSet Quotes { get; set; } public DbSet Contests { get; set; } public DbSet ContestEntries { get; set; } public DbSet Bugs { get; set; }