implement `UpdateBestBuddy`

This commit is contained in:
Alan Moon 2025-03-06 10:52:16 -08:00
parent 5bd62186f0
commit 6deebb947b
2 changed files with 30 additions and 0 deletions

View File

@ -1187,6 +1187,20 @@ public class ContentController : Controller {
else return Ok(false); else return Ok(false);
} }
[HttpPost]
[Produces("application/xml")]
[Route("ContentWebService.asmx/UpdateBestBuddy")]
[VikingSession]
public IActionResult SetBestBuddy(Viking viking, [FromForm] Guid buddyUserID, [FromForm] bool bestBuddy)
{
// get buddy
Viking? buddyViking = ctx.Vikings.FirstOrDefault(e => e.Uid == buddyUserID);
if (buddyViking != null)
return Ok(buddyService.UpdateBestBuddy(viking, buddyViking, bestBuddy));
else return Ok(false);
}
[HttpPost] [HttpPost]
[Produces("application/xml")] [Produces("application/xml")]
[Route("ContentWebService.asmx/GetBuddyList")] [Route("ContentWebService.asmx/GetBuddyList")]

View File

@ -77,6 +77,22 @@ public class BuddyService
} else return false; } else return false;
} }
public bool UpdateBestBuddy(Viking viking, Viking buddyViking, bool bestBuddy)
{
// find relation
Model.Buddy? buddy = ctx.Buddies.Where(e => e.VikingId == viking.Id || e.BuddyVikingId == viking.Id)
.FirstOrDefault(e => e.BuddyVikingId == buddyViking.Id || e.VikingId == buddyViking.Id);
if (buddy != null)
{
if (buddy.VikingId == viking.Id)
buddy.IsBestFriend1 = bestBuddy;
else buddy.IsBestFriend2 = bestBuddy;
return true;
} else return false;
}
public bool RemoveBuddy(Viking viking, Viking buddyViking) public bool RemoveBuddy(Viking viking, Viking buddyViking)
{ {
// find relation // find relation