modify game controller

This commit is contained in:
2023-07-09 21:17:43 +05:00
parent 96c68ea3d7
commit 13187e05d2
+13 -8
View File
@@ -98,22 +98,27 @@ namespace YandexGameServer.Controllers
}
[HttpPost("tags/add")]
public async Task SetTags(Tag tag)
public async Task<IActionResult> SetTags([FromBody] Tag tag)
{
_logger.LogWarning(Request.Body.ToString());
_logger.LogWarning($"{tag.city} записывают описание к метке {tag.game}");
var tagsInUse = await _databaseService.GetTagsAsync();
if(tagsInUse == null)
{
_logger.LogWarning($"{tag.city} записывают описание к метке {tag.game}");
await _databaseService.CreateAsync(tag);
return;
}
Tag? tagInUse = tagsInUse.Find(x => x.game == tag.game && x.city == tag.city);
if (!tagsInUse.Any(x => x.game == tag.game && x.city == tag.city))
{
_logger.LogWarning($"{tag.city} записывают описание к метке {tag.game}");
await _databaseService.CreateAsync(tag);
}
else
{
_logger.LogWarning($"{tag.city} обновляют описание у метки {tag.game}");
await _databaseService.UpdateAsync(tag);
}
if (tagInUse == null) await _databaseService.CreateAsync(tag);
else await _databaseService.UpdateAsync(tag);
return Ok();
}
}
}