forked from SoDOff-Project/sodoff
Profile Answers
-Add Ability For Profile Answers To Save -Add WoJS response for ``GetQuestions`` -Add ``Pain`` Mood To Question Data
This commit is contained in:
parent
1f190dd19a
commit
cc802043ec
@ -11,9 +11,11 @@ public class ProfileController : Controller {
|
|||||||
|
|
||||||
private readonly DBContext ctx;
|
private readonly DBContext ctx;
|
||||||
private AchievementService achievementService;
|
private AchievementService achievementService;
|
||||||
public ProfileController(DBContext ctx, AchievementService achievementService) {
|
private ProfileService profileService;
|
||||||
|
public ProfileController(DBContext ctx, AchievementService achievementService, ProfileService profileService) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.achievementService = achievementService;
|
this.achievementService = achievementService;
|
||||||
|
this.profileService = profileService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
@ -55,49 +57,61 @@ public class ProfileController : Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Produces("application/xml")]
|
// [Produces("application/xml")]
|
||||||
[Route("ProfileWebService.asmx/GetQuestions")]
|
[Route("ProfileWebService.asmx/GetQuestions")]
|
||||||
public IActionResult GetQuestions() {
|
public IActionResult GetQuestions() {
|
||||||
return Ok(new ProfileQuestionData {
|
return Ok(XmlUtil.ReadResourceXmlString("questiondata"));
|
||||||
Lists = new ProfileQuestionList[] {
|
|
||||||
new ProfileQuestionList {
|
//return Ok(new ProfileQuestionData {
|
||||||
ID = 4,
|
// Lists = new ProfileQuestionList[] {
|
||||||
Questions = new ProfileQuestion[] {
|
// new ProfileQuestionList {
|
||||||
new ProfileQuestion {
|
// ID = 4,
|
||||||
CategoryID = 3,
|
// Questions = new ProfileQuestion[] {
|
||||||
IsActive = "true", // this is a string, which makes me sad
|
// new ProfileQuestion {
|
||||||
Locale = "en-US",
|
// CategoryID = 3,
|
||||||
Ordinal = 1,
|
// IsActive = "true", // this is a string, which makes me sad
|
||||||
ID = 48,
|
// Locale = "en-US",
|
||||||
DisplayText = "How Did You Hear About US ?",
|
// Ordinal = 1,
|
||||||
Answers = new ProfileAnswer[] {
|
// ID = 48,
|
||||||
new ProfileAnswer {
|
// DisplayText = "How Did You Hear About US ?",
|
||||||
ID = 320,
|
// Answers = new ProfileAnswer[] {
|
||||||
DisplayText = "TV Commercial",
|
// new ProfileAnswer {
|
||||||
Locale = "en-US",
|
// ID = 320,
|
||||||
Ordinal = 1,
|
// DisplayText = "TV Commercial",
|
||||||
QuestionID = 48
|
// Locale = "en-US",
|
||||||
},
|
// Ordinal = 1,
|
||||||
new ProfileAnswer {
|
// QuestionID = 48
|
||||||
ID = 324,
|
// },
|
||||||
DisplayText = "I bought the RIders Of Berk DVD",
|
// new ProfileAnswer {
|
||||||
Locale = "en-US",
|
// ID = 324,
|
||||||
Ordinal = 5,
|
// DisplayText = "I bought the RIders Of Berk DVD",
|
||||||
QuestionID = 48
|
// Locale = "en-US",
|
||||||
},
|
// Ordinal = 5,
|
||||||
new ProfileAnswer {
|
// QuestionID = 48
|
||||||
ID = 325,
|
// },
|
||||||
DisplayText = "I bought the Defenders of Berk DVD",
|
// new ProfileAnswer {
|
||||||
Locale = "en-US",
|
// ID = 325,
|
||||||
Ordinal = 6,
|
// DisplayText = "I bought the Defenders of Berk DVD",
|
||||||
QuestionID = 48
|
// 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]
|
[HttpPost]
|
||||||
@ -141,7 +155,7 @@ public class ProfileController : Controller {
|
|||||||
FirstName = viking.Name,
|
FirstName = viking.Name,
|
||||||
MultiplayerEnabled = ClientVersion.IsMultiplayerSupported(apiKey),
|
MultiplayerEnabled = ClientVersion.IsMultiplayerSupported(apiKey),
|
||||||
Locale = "en-US", // placeholder
|
Locale = "en-US", // placeholder
|
||||||
GenderID = Gender.Male, // placeholder
|
GenderID = viking.Gender,
|
||||||
OpenChatEnabled = true,
|
OpenChatEnabled = true,
|
||||||
IsApproved = true,
|
IsApproved = true,
|
||||||
RegistrationDate = new DateTime(DateTime.Now.Ticks), // placeholder
|
RegistrationDate = new DateTime(DateTime.Now.Ticks), // placeholder
|
||||||
@ -174,7 +188,7 @@ public class ProfileController : Controller {
|
|||||||
AvatarInfo = avatar,
|
AvatarInfo = avatar,
|
||||||
AchievementCount = 0,
|
AchievementCount = 0,
|
||||||
MythieCount = 0,
|
MythieCount = 0,
|
||||||
AnswerData = new UserAnswerData { UserID = viking.Uid.ToString() },
|
AnswerData = new UserAnswerData { UserID = viking.Uid.ToString(), Answers = profileService.GetUserAnswers(viking)},
|
||||||
GameCurrency = currency.GameCurrency,
|
GameCurrency = currency.GameCurrency,
|
||||||
CashCurrency = currency.CashCurrency,
|
CashCurrency = currency.CashCurrency,
|
||||||
ActivityCount = 0,
|
ActivityCount = 0,
|
||||||
|
@ -19,6 +19,7 @@ public class DBContext : DbContext {
|
|||||||
public DbSet<GameData> GameData { get; set; } = null!;
|
public DbSet<GameData> GameData { get; set; } = null!;
|
||||||
public DbSet<GameDataPair> GameDataPairs { get; set; } = null!;
|
public DbSet<GameDataPair> GameDataPairs { get; set; } = null!;
|
||||||
public DbSet<AchievementPoints> AchievementPoints { get; set; } = null!;
|
public DbSet<AchievementPoints> AchievementPoints { get; set; } = null!;
|
||||||
|
public DbSet<ProfileAnswer> ProfileAnswers { get; set; } = null!;
|
||||||
private readonly IOptions<ApiServerConfig> config;
|
private readonly IOptions<ApiServerConfig> config;
|
||||||
|
|
||||||
public DBContext(IOptions<ApiServerConfig> config) {
|
public DBContext(IOptions<ApiServerConfig> config) {
|
||||||
@ -199,5 +200,9 @@ public class DBContext : DbContext {
|
|||||||
.HasOne(e => e.Viking)
|
.HasOne(e => e.Viking)
|
||||||
.WithMany(e => e.AchievementPoints)
|
.WithMany(e => e.AchievementPoints)
|
||||||
.HasForeignKey(e => e.VikingId);
|
.HasForeignKey(e => e.VikingId);
|
||||||
|
|
||||||
|
builder.Entity<ProfileAnswer>().HasOne(i => i.Viking)
|
||||||
|
.WithMany(i => i.ProfileAnswers)
|
||||||
|
.HasForeignKey(e => e.VikingId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
src/Model/ProfileAnswer.cs
Normal file
15
src/Model/ProfileAnswer.cs
Normal file
@ -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!;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace sodoff.Model;
|
namespace sodoff.Model;
|
||||||
@ -31,5 +31,6 @@ public class Viking {
|
|||||||
public virtual ICollection<PairData> PairData { get; set; } = null!;
|
public virtual ICollection<PairData> PairData { get; set; } = null!;
|
||||||
public virtual ICollection<InventoryItem> InventoryItems { get; set; } = null!;
|
public virtual ICollection<InventoryItem> InventoryItems { get; set; } = null!;
|
||||||
public virtual ICollection<GameData> GameData { get; set; } = null!;
|
public virtual ICollection<GameData> GameData { get; set; } = null!;
|
||||||
|
public virtual ICollection<ProfileAnswer> ProfileAnswers { get; set; } = null!;
|
||||||
public virtual Dragon? SelectedDragon { get; set; }
|
public virtual Dragon? SelectedDragon { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ builder.Services.AddScoped<RoomService>();
|
|||||||
builder.Services.AddScoped<InventoryService>();
|
builder.Services.AddScoped<InventoryService>();
|
||||||
builder.Services.AddScoped<AchievementService>();
|
builder.Services.AddScoped<AchievementService>();
|
||||||
builder.Services.AddScoped<GameDataService>();
|
builder.Services.AddScoped<GameDataService>();
|
||||||
|
builder.Services.AddScoped<ProfileService>();
|
||||||
|
|
||||||
bool assetServer = builder.Configuration.GetSection("AssetServer").GetValue<bool>("Enabled");
|
bool assetServer = builder.Configuration.GetSection("AssetServer").GetValue<bool>("Enabled");
|
||||||
string assetIP = builder.Configuration.GetSection("AssetServer").GetValue<string>("ListenIP");
|
string assetIP = builder.Configuration.GetSection("AssetServer").GetValue<string>("ListenIP");
|
||||||
|
2374
src/Resources/questiondata.xml
Normal file
2374
src/Resources/questiondata.xml
Normal file
File diff suppressed because it is too large
Load Diff
109
src/Services/ProfileService.cs
Normal file
109
src/Services/ProfileService.cs
Normal file
@ -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<ProfileUserAnswer> userAnswers = new List<ProfileUserAnswer>();
|
||||||
|
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<ProfileQuestionData>(XmlUtil.ReadResourceXmlString("questiondata"));
|
||||||
|
|
||||||
|
List<Schema.ProfileAnswer> allAnswersFromData = new List<Schema.ProfileAnswer>();
|
||||||
|
List<ProfileQuestion> allQuestionsFromData = new List<ProfileQuestion>();
|
||||||
|
|
||||||
|
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!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -50,6 +50,7 @@
|
|||||||
<None Remove="Resources\defaultmissionlist.xml" />
|
<None Remove="Resources\defaultmissionlist.xml" />
|
||||||
<None Remove="Resources\defaultmissionlistv1.xml" />
|
<None Remove="Resources\defaultmissionlistv1.xml" />
|
||||||
<None Remove="Resources\defaultmissionlistmam.xml" />
|
<None Remove="Resources\defaultmissionlistmam.xml" />
|
||||||
|
<None Remove="Resources\questiondata.xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="Resources\childlist.xml">
|
<None Update="Resources\childlist.xml">
|
||||||
@ -117,5 +118,8 @@
|
|||||||
<EmbeddedResource Include="Resources\defaultmissionlistmam.xml">
|
<EmbeddedResource Include="Resources\defaultmissionlistmam.xml">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="Resources\questiondata.xml">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user