From 6deebb947b53e429475aaaae591dbc2c6c267a70 Mon Sep 17 00:00:00 2001 From: AlanMoonbase Date: Thu, 6 Mar 2025 10:52:16 -0800 Subject: [PATCH] implement ``UpdateBestBuddy`` --- src/Controllers/Common/ContentController.cs | 14 ++++++++++++++ src/Services/BuddyService.cs | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index 4a1293f..7d033aa 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -1187,6 +1187,20 @@ public class ContentController : Controller { 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] [Produces("application/xml")] [Route("ContentWebService.asmx/GetBuddyList")] diff --git a/src/Services/BuddyService.cs b/src/Services/BuddyService.cs index b309f17..0ca60ee 100644 --- a/src/Services/BuddyService.cs +++ b/src/Services/BuddyService.cs @@ -77,6 +77,22 @@ public class BuddyService } 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) { // find relation