From 67a0b9f36030d47190f68886f7ecee69c8406afd Mon Sep 17 00:00:00 2001 From: Hipposgrumm Date: Sun, 19 Oct 2025 11:36:08 -0600 Subject: [PATCH] Added group name validation. Also made name validation a switch statement (faster). --- src/Controllers/Common/ContentController.cs | 26 +++++++++++++-------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index bfe965f..319ceec 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -204,17 +204,23 @@ public class ContentController : Controller { // Check if name populated NameValidationRequest request = XmlUtil.DeserializeXml(nameValidationRequest); - if (request.Category == NameCategory.Default) { - // This is an avatar we are checking - // Check if viking exists - bool exists = ctx.Vikings.Count(e => e.Name == request.Name) > 0; - NameValidationResult result = exists ? NameValidationResult.NotUnique : NameValidationResult.Ok; - return Ok(new NameValidationResponse { Result = result}); - - } else { - // TODO: pets, groups, default - return Ok(); + bool exists; + switch (request.Category) { + case NameCategory.Default: + // This is an avatar we are checking + // Check if viking exists + exists = ctx.Vikings.Any(e => e.Name == request.Name); + break; + case NameCategory.Group: + exists = ctx.Groups.Any(e => e.Name == request.Name); + break; + default: + // TODO: pets, default + return Ok(); } + + NameValidationResult result = exists ? NameValidationResult.NotUnique : NameValidationResult.Ok; + return Ok(new NameValidationResponse { Result = result }); } [HttpPost]