diff --git a/src/Controllers/Common/ProfileController.cs b/src/Controllers/Common/ProfileController.cs index f414b65..1c8873e 100644 --- a/src/Controllers/Common/ProfileController.cs +++ b/src/Controllers/Common/ProfileController.cs @@ -11,9 +11,11 @@ public class ProfileController : Controller { private readonly DBContext ctx; private AchievementService achievementService; - public ProfileController(DBContext ctx, AchievementService achievementService) { + private ProfileService profileService; + public ProfileController(DBContext ctx, AchievementService achievementService, ProfileService profileService) { this.ctx = ctx; this.achievementService = achievementService; + this.profileService = profileService; } [HttpPost] @@ -55,49 +57,61 @@ public class ProfileController : Controller { } [HttpPost] - [Produces("application/xml")] + // [Produces("application/xml")] [Route("ProfileWebService.asmx/GetQuestions")] public IActionResult GetQuestions() { - return Ok(new ProfileQuestionData { - Lists = new ProfileQuestionList[] { - new ProfileQuestionList { - ID = 4, - Questions = new ProfileQuestion[] { - new ProfileQuestion { - CategoryID = 3, - IsActive = "true", // this is a string, which makes me sad - Locale = "en-US", - Ordinal = 1, - ID = 48, - DisplayText = "How Did You Hear About US ?", - Answers = new ProfileAnswer[] { - new ProfileAnswer { - ID = 320, - DisplayText = "TV Commercial", - Locale = "en-US", - Ordinal = 1, - QuestionID = 48 - }, - new ProfileAnswer { - ID = 324, - DisplayText = "I bought the RIders Of Berk DVD", - Locale = "en-US", - Ordinal = 5, - QuestionID = 48 - }, - new ProfileAnswer { - ID = 325, - DisplayText = "I bought the Defenders of Berk DVD", - Locale = "en-US", - Ordinal = 6, - QuestionID = 48 - } - } - } - } - } - } - }); + return Ok(XmlUtil.ReadResourceXmlString("questiondata")); + + //return Ok(new ProfileQuestionData { + // Lists = new ProfileQuestionList[] { + // new ProfileQuestionList { + // ID = 4, + // Questions = new ProfileQuestion[] { + // new ProfileQuestion { + // CategoryID = 3, + // IsActive = "true", // this is a string, which makes me sad + // Locale = "en-US", + // Ordinal = 1, + // ID = 48, + // DisplayText = "How Did You Hear About US ?", + // Answers = new ProfileAnswer[] { + // new ProfileAnswer { + // ID = 320, + // DisplayText = "TV Commercial", + // Locale = "en-US", + // Ordinal = 1, + // QuestionID = 48 + // }, + // new ProfileAnswer { + // ID = 324, + // DisplayText = "I bought the RIders Of Berk DVD", + // Locale = "en-US", + // Ordinal = 5, + // QuestionID = 48 + // }, + // new ProfileAnswer { + // ID = 325, + // DisplayText = "I bought the Defenders of Berk DVD", + // Locale = "en-US", + // Ordinal = 6, + // QuestionID = 48 + // } + // } + // } + // } + // } + // } + // }); + } + + [HttpPost] + [Produces("application/xml")] + [Route("ProfileWebService.asmx/SetUserProfileAnswers")] + [VikingSession] + public IActionResult SetUserProfileAnswers(Viking viking, [FromForm] int profileAnswerIDs) + { + ProfileQuestion questionFromaId = profileService.GetQuestionFromAnswerId(profileAnswerIDs); + return Ok(profileService.SetAnswer(viking, questionFromaId.ID, profileAnswerIDs)); } [HttpPost] @@ -141,7 +155,7 @@ public class ProfileController : Controller { FirstName = viking.Name, MultiplayerEnabled = ClientVersion.IsMultiplayerSupported(apiKey), Locale = "en-US", // placeholder - GenderID = Gender.Male, // placeholder + GenderID = viking.Gender, OpenChatEnabled = true, IsApproved = true, RegistrationDate = new DateTime(DateTime.Now.Ticks), // placeholder @@ -174,7 +188,7 @@ public class ProfileController : Controller { AvatarInfo = avatar, AchievementCount = 0, MythieCount = 0, - AnswerData = new UserAnswerData { UserID = viking.Uid.ToString() }, + AnswerData = new UserAnswerData { UserID = viking.Uid.ToString(), Answers = profileService.GetUserAnswers(viking)}, GameCurrency = currency.GameCurrency, CashCurrency = currency.CashCurrency, ActivityCount = 0, diff --git a/src/Model/DBContext.cs b/src/Model/DBContext.cs index dc8b95e..1abaf55 100644 --- a/src/Model/DBContext.cs +++ b/src/Model/DBContext.cs @@ -19,6 +19,7 @@ public class DBContext : DbContext { public DbSet GameData { get; set; } = null!; public DbSet GameDataPairs { get; set; } = null!; public DbSet AchievementPoints { get; set; } = null!; + public DbSet ProfileAnswers { get; set; } = null!; private readonly IOptions config; public DBContext(IOptions config) { @@ -199,5 +200,9 @@ public class DBContext : DbContext { .HasOne(e => e.Viking) .WithMany(e => e.AchievementPoints) .HasForeignKey(e => e.VikingId); + + builder.Entity().HasOne(i => i.Viking) + .WithMany(i => i.ProfileAnswers) + .HasForeignKey(e => e.VikingId); } } diff --git a/src/Model/ProfileAnswer.cs b/src/Model/ProfileAnswer.cs new file mode 100644 index 0000000..4aae801 --- /dev/null +++ b/src/Model/ProfileAnswer.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations; + +namespace sodoff.Model +{ + public class ProfileAnswer + { + [Key] + public int Id { get; set; } + public int VikingId { get; set; } + public int QuestionID { get; set; } + public int AnswerID { get; set; } + + public virtual Viking Viking { get; set; } = null!; + } +} diff --git a/src/Model/Viking.cs b/src/Model/Viking.cs index 6b0e9af..731deb0 100644 --- a/src/Model/Viking.cs +++ b/src/Model/Viking.cs @@ -1,4 +1,4 @@ -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations; namespace sodoff.Model; @@ -31,5 +31,6 @@ public class Viking { public virtual ICollection PairData { get; set; } = null!; public virtual ICollection InventoryItems { get; set; } = null!; public virtual ICollection GameData { get; set; } = null!; + public virtual ICollection ProfileAnswers { get; set; } = null!; public virtual Dragon? SelectedDragon { get; set; } } diff --git a/src/Program.cs b/src/Program.cs index 79f851a..a6ce21c 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -33,6 +33,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); bool assetServer = builder.Configuration.GetSection("AssetServer").GetValue("Enabled"); string assetIP = builder.Configuration.GetSection("AssetServer").GetValue("ListenIP"); diff --git a/src/Resources/questiondata.xml b/src/Resources/questiondata.xml new file mode 100644 index 0000000..965c1d4 --- /dev/null +++ b/src/Resources/questiondata.xml @@ -0,0 +1,2374 @@ + + + + 1 + + 1 + https://jsmedia.alanmoon.net/Content/PlayerData/Favs/IconColor.png + true + en-US + 1 + 21 + Color + + 64 + Ruby Red + + en-US + 1 + 21 + + + 69 + Tangerine Orange + + en-US + 2 + 21 + + + 51 + Canary Yellow + + en-US + 3 + 21 + + + 66 + Shamrock Green + + en-US + 4 + 21 + + + 53 + Denim Blue + + en-US + 5 + 21 + + + 63 + Purple Plum + + en-US + 6 + 21 + + + 39 + Ballerina Pink + + en-US + 7 + 21 + + + 57 + Hot Pink + + en-US + 8 + 21 + + + 68 + Snow White + + en-US + 9 + 21 + + + 49 + Black as Night + + en-US + 10 + 21 + + + 56 + Gray Cloud + + en-US + 11 + 21 + + + 40 + Bark Brown + + en-US + 12 + 21 + + + 54 + Desert Sand Tan + + en-US + 13 + 21 + + + 50 + Brick Red + + en-US + 14 + 21 + + + 59 + Lemon Yellow + + en-US + 15 + 21 + + + 55 + Electric Lime + + en-US + 16 + 21 + + + 62 + Olive Green + + en-US + 17 + 21 + + + 65 + Sea Foam Green + + en-US + 18 + 21 + + + 38 + Baby Blue + + en-US + 19 + 21 + + + 52 + Caribbean Teal + + en-US + 20 + 21 + + + 61 + Midnight Blue + + en-US + 21 + 21 + + + 67 + Sky Blue + + en-US + 22 + 21 + + + 58 + Indigo-go + + en-US + 23 + 21 + + + 60 + Lush Lavender + + en-US + 24 + 21 + + + + 1 + https://jsmedia.alanmoon.net/Content/PlayerData/Favs/IconFood.png + true + en-US + 2 + 22 + Food + + 48 + Anything with bacon + + en-US + 1 + 22 + + + 70 + Burritos + + en-US + 2 + 22 + + + 71 + Cake + + en-US + 3 + 22 + + + 72 + Candy + + en-US + 4 + 22 + + + 73 + Cereal + + en-US + 5 + 22 + + + 74 + Cheese + + en-US + 6 + 22 + + + 75 + Chicken + + en-US + 7 + 22 + + + 76 + Chips + + en-US + 8 + 22 + + + 77 + Chocolate + + en-US + 9 + 22 + + + 78 + Cookies + + en-US + 10 + 22 + + + 79 + Fast food + + en-US + 11 + 22 + + + 80 + French fries + + en-US + 12 + 22 + + + 81 + Fruit + + en-US + 13 + 22 + + + 82 + Hamburgers + + en-US + 14 + 22 + + + 83 + Hot dogs + + en-US + 15 + 22 + + + 84 + Hummus + + en-US + 16 + 22 + + + 85 + Ice cream + + en-US + 17 + 22 + + + 86 + Lasagna + + en-US + 18 + 22 + + + 87 + Mac and cheese + + en-US + 19 + 22 + + + 94 + My mom's cooking + + en-US + 20 + 22 + + + 88 + Nachos + + en-US + 21 + 22 + + + 89 + Not anchovies + + en-US + 22 + 22 + + + 90 + Not cow tongue + + en-US + 23 + 22 + + + 91 + Not fried Twinkies + + en-US + 24 + 22 + + + 92 + Not frog legs + + en-US + 25 + 22 + + + 93 + Not liver + + en-US + 26 + 22 + + + 95 + Not sauerkraut + + en-US + 27 + 22 + + + 96 + Not toe jam + + en-US + 28 + 22 + + + 97 + Not vegetables + + en-US + 29 + 22 + + + 98 + Pasta + + en-US + 30 + 22 + + + 99 + PB&J sandwiches + + en-US + 31 + 22 + + + 100 + Pizza + + en-US + 32 + 22 + + + 101 + Salad + + en-US + 33 + 22 + + + 102 + Seafood + + en-US + 34 + 22 + + + 103 + Steak + + en-US + 35 + 22 + + + 104 + Sushi + + en-US + 36 + 22 + + + 105 + Tacos + + en-US + 37 + 22 + + + 106 + Tofu + + en-US + 38 + 22 + + + + 1 + https://jsmedia.alanmoon.net/Content/PlayerData/Favs/IconMusic.png + true + en-US + 3 + 23 + Music + + 35 + Alternative Rock + + en-US + 1 + 23 + + + 36 + Blues + + en-US + 2 + 23 + + + 107 + Classical + + en-US + 3 + 23 + + + 108 + Country + + en-US + 4 + 23 + + + 109 + Heavy Metal + + en-US + 5 + 23 + + + 110 + Hip hop + + en-US + 6 + 23 + + + 111 + House + + en-US + 7 + 23 + + + 112 + Indie + + en-US + 8 + 23 + + + 113 + Jazz + + en-US + 9 + 23 + + + 114 + Punk Rock + + en-US + 10 + 23 + + + 115 + Rap + + en-US + 11 + 23 + + + 116 + Reggae + + en-US + 12 + 23 + + + 117 + Avril Lavigne + + en-US + 13 + 23 + + + 118 + Beyonce + + en-US + 14 + 23 + + + 119 + Big Time Rush + + en-US + 15 + 23 + + + 120 + Black Eyed Peas + + en-US + 16 + 23 + + + 121 + Britney Spears + + en-US + 17 + 23 + + + 122 + Bruno Mars + + en-US + 18 + 23 + + + 123 + Carrie Underwood + + en-US + 19 + 23 + + + 124 + Chris Brown + + en-US + 20 + 23 + + + 125 + Christina Aguilera + + en-US + 21 + 23 + + + 126 + Eminem + + en-US + 22 + 23 + + + 127 + Glee Cast + + en-US + 23 + 23 + + + 128 + Gwen Stefani + + en-US + 24 + 23 + + + 129 + Jennifer Lopez + + en-US + 25 + 23 + + + 130 + Jonas Brothers + + en-US + 26 + 23 + + + 131 + Justin Bieber + + en-US + 27 + 23 + + + 132 + Katy Perry + + en-US + 28 + 23 + + + 133 + Ke$ha + + en-US + 29 + 23 + + + 134 + Kelly Clarkson + + en-US + 30 + 23 + + + 135 + Kings of Leon + + en-US + 31 + 23 + + + 136 + Lady Antebellum + + en-US + 32 + 23 + + + 137 + Lady Gaga + + en-US + 33 + 23 + + + 138 + Leona Lewis + + en-US + 34 + 23 + + + 139 + Michael Jackson + + en-US + 35 + 23 + + + 140 + Miley Cyrus + + en-US + 36 + 23 + + + 141 + Nikki Minaj + + en-US + 37 + 23 + + + 142 + Pink + + en-US + 38 + 23 + + + 143 + Rihanna + + en-US + 39 + 23 + + + 144 + Selena Gomez + + en-US + 40 + 23 + + + 145 + Sugarland + + en-US + 41 + 23 + + + 146 + Taio Cruz + + en-US + 42 + 23 + + + 147 + Taylor Swift + + en-US + 43 + 23 + + + 148 + Usher + + en-US + 44 + 23 + + + 149 + Zac Brown Band + + en-US + 45 + 23 + + + + 1 + https://jsmedia.alanmoon.net/Content/PlayerData/Favs/IconAnimal.png + true + en-US + 4 + 29 + Animal + + 176 + Alligator + + en-US + 1 + 29 + + + 158 + Bear + + en-US + 2 + 29 + + + 152 + Bird + + en-US + 3 + 29 + + + 167 + Butterfly + + en-US + 4 + 29 + + + 151 + Cat + + en-US + 5 + 29 + + + 170 + Cheetah + + en-US + 6 + 29 + + + 150 + Dog + + en-US + 7 + 29 + + + 174 + Dolphin + + en-US + 8 + 29 + + + 179 + Elephant + + en-US + 9 + 29 + + + 161 + Fish + + en-US + 10 + 29 + + + 175 + Frog + + en-US + 11 + 29 + + + 155 + Goat + + en-US + 12 + 29 + + + 178 + Hamster + + en-US + 13 + 29 + + + 153 + Horse + + en-US + 14 + 29 + + + 163 + Kangaroo + + en-US + 15 + 29 + + + 162 + Koala + + en-US + 16 + 29 + + + 156 + Lion + + en-US + 17 + 29 + + + 177 + Lizard + + en-US + 18 + 29 + + + 172 + Monkey + + en-US + 19 + 29 + + + 169 + Otter + + en-US + 20 + 29 + + + 164 + Panda bear + + en-US + 21 + 29 + + + 181 + Penguin + + en-US + 22 + 29 + + + 154 + Pig + + en-US + 23 + 29 + + + 183 + Rabbit + + en-US + 24 + 29 + + + 180 + Rhinoceros + + en-US + 25 + 29 + + + 160 + Shark + + en-US + 26 + 29 + + + 171 + Sloth + + en-US + 27 + 29 + + + 173 + Snake + + en-US + 28 + 29 + + + 168 + Spider + + en-US + 29 + 29 + + + 157 + Tiger + + en-US + 30 + 29 + + + 166 + Unicorn + + en-US + 31 + 29 + + + 159 + Whale + + en-US + 32 + 29 + + + 165 + Wolf + + en-US + 33 + 29 + + + 182 + Zebra + + en-US + 34 + 29 + + + + 1 + https://jsmedia.alanmoon.net/Content/PlayerData/Favs/IconMovies.png + true + en-US + 5 + 30 + Type of Movie + + 184 + Drama + + en-US + 1 + 30 + + + 185 + Action + + en-US + 2 + 30 + + + 186 + Thriller + + en-US + 3 + 30 + + + 187 + Romantic Comedy + + en-US + 4 + 30 + + + 188 + Hero/Heroine + + en-US + 5 + 30 + + + 189 + Science Fiction + + en-US + 6 + 30 + + + 190 + Horror + + en-US + 7 + 30 + + + 191 + Western + + en-US + 8 + 30 + + + 192 + Animated + + en-US + 9 + 30 + + + 193 + Cartoon + + en-US + 10 + 30 + + + 194 + Documentary + + en-US + 11 + 30 + + + 195 + Fantasy + + en-US + 12 + 30 + + + 196 + Family + + en-US + 13 + 30 + + + 197 + Mystery + + en-US + 14 + 30 + + + 198 + Adventure + + en-US + 15 + 30 + + + 199 + Comedy + + en-US + 16 + 30 + + + 200 + Musical + + en-US + 17 + 30 + + + + 1 + https://jsmedia.alanmoon.net/Content/PlayerData/Favs/IconSport.png + true + en-US + 6 + 31 + Sport + + 201 + Badminton + + en-US + 1 + 31 + + + 202 + Baseball + + en-US + 2 + 31 + + + 203 + Basketball + + en-US + 3 + 31 + + + 204 + Cheerleading + + en-US + 4 + 31 + + + 205 + Cricket + + en-US + 5 + 31 + + + 206 + Cross Country + + en-US + 6 + 31 + + + 207 + Cycling + + en-US + 7 + 31 + + + 208 + Diving + + en-US + 8 + 31 + + + 209 + Dodgeball + + en-US + 9 + 31 + + + 210 + Football + + en-US + 10 + 31 + + + 211 + Golf + + en-US + 11 + 31 + + + 212 + Gymnastics + + en-US + 12 + 31 + + + 213 + Handball + + en-US + 13 + 31 + + + 214 + Hockey + + en-US + 14 + 31 + + + 215 + Karate + + en-US + 15 + 31 + + + 216 + Ping Pong + + en-US + 16 + 31 + + + 217 + Racing + + en-US + 17 + 31 + + + 218 + Racquetball + + en-US + 18 + 31 + + + 219 + Rugby + + en-US + 19 + 31 + + + 220 + Soccer + + en-US + 20 + 31 + + + 221 + Softball + + en-US + 21 + 31 + + + 222 + Swimming + + en-US + 22 + 31 + + + 223 + Tennis + + en-US + 23 + 31 + + + 224 + Tetherball + + en-US + 24 + 31 + + + 225 + Track and Field + + en-US + 25 + 31 + + + 226 + Volleyball + + en-US + 26 + 31 + + + + + 2 + + 2 + + true + en-US + 1 + 32 + Gender + + 227 + Boy + https://jsmedia.alanmoon.net/Content/PlayerData/Gender/IconGenderBoy.png + en-US + 1 + 32 + + + 228 + Girl + https://jsmedia.alanmoon.net/Content/PlayerData/Gender/IconGenderGirl.png + en-US + 2 + 32 + + + + 2 + + true + en-US + 2 + 33 + Country + + 231 + United States + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryUSA.png + en-US + 1 + 33 + + + 256 + Mexico + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryMexico.png + en-US + 2 + 33 + + + 237 + Canada + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryCanada.png + en-US + 3 + 33 + + + 230 + United Kingdom + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryUK.png + en-US + 4 + 33 + + + 233 + Australia + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryAustralia.png + en-US + 5 + 33 + + + 232 + Argentina + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryArgentina.png + en-US + 6 + 33 + + + 234 + Austria + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryAustria.png + en-US + 7 + 33 + + + 235 + Belgium + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryBelgium.png + en-US + 8 + 33 + + + 236 + Brazil + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryBrazil.png + en-US + 9 + 33 + + + 238 + Chile + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryChile.png + en-US + 10 + 33 + + + 239 + China + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryChina.png + en-US + 11 + 33 + + + 311 + Columbia + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryColumbia.png + en-US + 12 + 33 + + + 240 + Costa Rica + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryCostaRica.png + en-US + 13 + 33 + + + 241 + Croatia + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryCroatia.png + en-US + 14 + 33 + + + 312 + Czech Republic + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryCzechRep.png + en-US + 15 + 33 + + + 242 + Denmark + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryDenmark.png + en-US + 16 + 33 + + + 276 + Dominican Republic + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryDomRep.png + en-US + 17 + 33 + + + 313 + Ecuador + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryEcuador.png + en-US + 18 + 33 + + + 243 + Egypt + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryEgypt.png + en-US + 19 + 33 + + + 244 + Finland + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryFinland.png + en-US + 20 + 33 + + + 245 + France + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryFrance.png + en-US + 21 + 33 + + + 246 + Germany + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryGermany.png + en-US + 22 + 33 + + + 247 + Greece + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryGreece.png + en-US + 23 + 33 + + + 248 + Guam + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryGuam.png + en-US + 24 + 33 + + + 249 + Guatemala + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryGuatemala.png + en-US + 25 + 33 + + + 250 + Hong Kong + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryHongKong.png + en-US + 26 + 33 + + + 251 + Hungary + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryHungary.png + en-US + 27 + 33 + + + 277 + Iceland + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryIceland.png + en-US + 28 + 33 + + + 252 + India + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryIndia.png + en-US + 29 + 33 + + + 314 + Indonesia + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryIndonesia.png + en-US + 30 + 33 + + + 253 + Ireland + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryIreland.png + en-US + 31 + 33 + + + 278 + Israel + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryIsrael.png + en-US + 32 + 33 + + + 254 + Italy + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryItaly.png + en-US + 33 + 33 + + + 279 + Jamaica + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryJamaica.png + en-US + 34 + 33 + + + 255 + Japan + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryJapan.png + en-US + 35 + 33 + + + 315 + Lithuania + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryLithuania.png + en-US + 36 + 33 + + + 280 + Madagascar + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryMadagascar.png + en-US + 37 + 33 + + + 316 + Malaysia + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryMalaysia.png + en-US + 38 + 33 + + + 317 + Morocco + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryMorocco.png + en-US + 39 + 33 + + + 257 + Netherlands + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryNetherlands.png + en-US + 40 + 33 + + + 258 + New Zealand + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryNewZ.png + en-US + 41 + 33 + + + 259 + Nigeria + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryNigeria.png + en-US + 42 + 33 + + + 281 + Norway + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryNorway.png + en-US + 43 + 33 + + + 282 + Pakistan + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryPakistan.png + en-US + 44 + 33 + + + 283 + Paraguay + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryParaguay.png + en-US + 45 + 33 + + + 260 + Peru + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryPeru.png + en-US + 46 + 33 + + + 261 + Philippines + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryPhilippines.png + en-US + 47 + 33 + + + 262 + Poland + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryPoland.png + en-US + 48 + 33 + + + 263 + Portugal + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryPortugal.png + en-US + 49 + 33 + + + 264 + Puerto Rico + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryPuertoRico.png + en-US + 50 + 33 + + + 318 + Romania + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryRomania.png + en-US + 51 + 33 + + + 265 + Russia + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryRussia.png + en-US + 52 + 33 + + + 284 + Saudi Arabia + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountrySaudiA.png + en-US + 53 + 33 + + + 266 + Singapore + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountrySingapore.png + en-US + 54 + 33 + + + 285 + South Africa + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountrySouthAF.png + en-US + 55 + 33 + + + 286 + South Korea + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountrySouthK.png + en-US + 56 + 33 + + + 267 + Spain + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountrySpain.png + en-US + 57 + 33 + + + 268 + Sweden + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountrySweden.png + en-US + 58 + 33 + + + 269 + Switzerland + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountrySwitzer.png + en-US + 59 + 33 + + + 270 + Taiwan + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryTaiwan.png + en-US + 60 + 33 + + + 271 + Thailand + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryThailand.png + en-US + 61 + 33 + + + 272 + Turkey + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryTurkey.png + en-US + 62 + 33 + + + 273 + Ukraine + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryUkraine.png + en-US + 63 + 33 + + + 274 + United Arab Emirates + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryUAE.png + en-US + 64 + 33 + + + 287 + Uruguay + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryUruguay.png + en-US + 65 + 33 + + + 319 + Venezuela + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryVenezuela.png + en-US + 66 + 33 + + + 275 + Vietnam + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoCountryVietnam.png + en-US + 67 + 33 + + + 444 + Pride + https://jsmedia.alanmoon.net/Content/PlayerData/CountryFlags/IcoPride.png + en-US + 68 + 33 + + + + 2 + + true + en-US + 3 + 34 + Mood + + 288 + Gleeful + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodGleeful.png + en-US + 1 + 34 + + + 289 + Furious + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodFurious.png + en-US + 2 + 34 + + + 290 + Fabulous + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodFabulous.png + en-US + 3 + 34 + + + 291 + Sporty + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodSporty.png + en-US + 4 + 34 + + + 292 + Amped + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodAmped.png + en-US + 5 + 34 + + + 293 + Blah + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodBlah.png + en-US + 6 + 34 + + + 294 + Perplexed + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodPerplexed.png + en-US + 7 + 34 + + + 295 + Sleepy + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodSleepy.png + en-US + 8 + 34 + + + 296 + Embarrassed + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodEmbarrassed.png + en-US + 9 + 34 + + + 297 + Sassy + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodSassy.png + en-US + 10 + 34 + + + 298 + Amused + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodAmused.png + en-US + 11 + 34 + + + 299 + Tricky + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodTricky.png + en-US + 12 + 34 + + + 300 + Loony + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodLoony.png + en-US + 13 + 34 + + + 301 + Artsy + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodArtsy.png + en-US + 14 + 34 + + + 302 + Musical + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodMusical.png + en-US + 15 + 34 + + + 303 + Brokenhearted + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodBrokenHearted.png + en-US + 16 + 34 + + + 304 + Nerdy + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodNerdy.png + en-US + 17 + 34 + + + 305 + Messy + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodMessy.png + en-US + 18 + 34 + + + 306 + Cheesy + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodCheesy.png + en-US + 19 + 34 + + + 307 + Brainy + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodBrainy.png + en-US + 20 + 34 + + + 308 + Happy + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodHappy.png + en-US + 21 + 34 + + + 309 + Sad + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoMoodSad.png + en-US + 22 + 34 + + + 310 + Pain + https://jsmedia.alanmoon.net/Content/PlayerData/Mood/IcoPain.png + en-US + 23 + 34 + + + + + 5 + + 3 + + true + en-US + 1 + 49 + How Did You Hear About US ? + + 340 + TV Commercial + + en-US + 1 + 49 + + + 327 + A Friend told me + + en-US + 2 + 49 + + + 328 + Web Search + + en-US + 3 + 49 + + + 329 + I was invited by a friend through email/social media + + en-US + 4 + 49 + + + 330 + I bought the Madagascar DVD + + en-US + 5 + 49 + + + 331 + An online ad + + en-US + 6 + 49 + + + 332 + Other + + en-US + 7 + 49 + + + + diff --git a/src/Services/ProfileService.cs b/src/Services/ProfileService.cs new file mode 100644 index 0000000..1e0a897 --- /dev/null +++ b/src/Services/ProfileService.cs @@ -0,0 +1,109 @@ +using sodoff.Model; +using sodoff.Schema; +using sodoff.Util; + +namespace sodoff.Services +{ + public class ProfileService + { + private readonly DBContext ctx; + + public ProfileService(DBContext ctx) + { + this.ctx = ctx; + } + + public bool SetAnswer(Viking viking, int qId, int aId) + { + // check if answer is in the database already, edit it with new answer id if it does + Model.ProfileAnswer? existingAnswer = viking.ProfileAnswers.FirstOrDefault(e => e.QuestionID == qId); + if(existingAnswer != null) + { + existingAnswer.AnswerID = aId; + ctx.SaveChanges(); + return true; + } + + // create an answer and store it in database + + Model.ProfileAnswer answer = new Model.ProfileAnswer + { + VikingId = viking.Id, + AnswerID = aId, + QuestionID = qId, + }; + + viking.ProfileAnswers.Add(answer); + ctx.SaveChanges(); + + return true; + } + + public ProfileUserAnswer[] GetUserAnswers(Viking viking) + { + // create a profile user answer based on each answer on viking + + List userAnswers = new List(); + foreach(Model.ProfileAnswer answer in viking.ProfileAnswers) + { + ProfileUserAnswer userAnswer = new ProfileUserAnswer + { + AnswerID = answer.AnswerID, + QuestionID = answer.QuestionID + }; + userAnswers.Add(userAnswer); + } + + return userAnswers.ToArray(); + } + + public ProfileUserAnswer GetUserAnswerFromQuestionId(Viking viking, int qId) + { + // check if answer exists + Model.ProfileAnswer profileAnswer = viking.ProfileAnswers.FirstOrDefault(e => e.QuestionID == qId); + + if(profileAnswer != null) + { + ProfileUserAnswer profileUserAnswer = new ProfileUserAnswer + { + QuestionID = profileAnswer.QuestionID, + AnswerID = profileAnswer.AnswerID + }; + return profileUserAnswer; + } + + return null; + } + + public ProfileQuestion GetQuestionFromAnswerId(int aId) + { + ProfileQuestionData questionData = XmlUtil.DeserializeXml(XmlUtil.ReadResourceXmlString("questiondata")); + + List allAnswersFromData = new List(); + List allQuestionsFromData = new List(); + + foreach(var list in questionData.Lists) + { + foreach(var question in list.Questions) + { + allQuestionsFromData.Add(question); + foreach(var answer in question.Answers) + { + allAnswersFromData.Add(answer); + } + } + } + + Schema.ProfileAnswer profileAnswer = allAnswersFromData.FirstOrDefault(e => e.ID == aId); + + if (profileAnswer != null) + { + ProfileQuestion questionFromAnswer = allQuestionsFromData.FirstOrDefault(e => e.ID == profileAnswer.QuestionID); + if (questionFromAnswer != null) return questionFromAnswer; + else return null!; + } + + return null!; + } + } +} diff --git a/src/sodoff.csproj b/src/sodoff.csproj index 9711f75..3408993 100644 --- a/src/sodoff.csproj +++ b/src/sodoff.csproj @@ -50,6 +50,7 @@ + @@ -117,5 +118,8 @@ PreserveNewest + + PreserveNewest +