Browse Source

fix actionresult

master
Serg A. Verevkin 10 months ago
parent
commit
ce4f2fc22e
  1. 29
      Controllers/FieldController.cs
  2. 11
      Model/RandomField.cs
  3. 3
      TextFile.md

29
Controllers/FieldController.cs

@ -30,20 +30,37 @@ namespace WebApplication1.Controllers
[HttpPost("new")] [HttpPost("new")]
public Field StartNewGame() public ActionResult<Field> StartNewGame()
{ {
return _fm.StartNewGame(); Field result = _fm.StartNewGame();
if (result == null)
{
return NotFound();
}
return Ok(result);
} }
[HttpPost("move")] [HttpPost("move")]
public Field Move(string identifier) public ActionResult<Field> Move(string identifier)
{
Field result = _fm.Move(identifier);
if (result == null)
{ {
return _fm.Move(identifier); return NotFound();
}
return Ok(result);
} }
[HttpGet("list")] [HttpGet("list")]
public Field List(string identifier) public ActionResult<Field> List(string identifier)
{ {
return _fm.List(identifier); var result = _fm.List(identifier);
if (result == null)
{
return NotFound();
}
return Ok(result);
} }
} }

11
Model/RandomField.cs

@ -4,6 +4,9 @@ namespace WebApplication1
{ {
public class RandomField : Field public class RandomField : Field
{ {
private const int MaxTypeValue = 1;
private const int MaxColorValue = 2;
public RandomField(int iCount) public RandomField(int iCount)
{ {
Random rr = new Random(); Random rr = new Random();
@ -11,10 +14,10 @@ namespace WebApplication1
{ {
this.Figures.Add(new Figure() this.Figures.Add(new Figure()
{ {
FigureColor = rr.Next(2), FigureColor = rr.Next(MaxColorValue),
FigureType = rr.Next(1), FigureType = rr.Next(MaxTypeValue) + 1,
PosX = rr.Next(FigureMover.FieldXMin, FigureMover.FieldXMax), PosX = rr.Next(FigureMover.FieldXMin, FigureMover.FieldXMax + 1),
PosY = rr.Next(FigureMover.FieldYMin, FigureMover.FieldYMax), PosY = rr.Next(FigureMover.FieldYMin, FigureMover.FieldYMax + 1),
}); });
} }
} }

3
TextFile.md

@ -1,5 +1,6 @@
# Задача # Задача
Продемонстрировать работающий сервис с реализацией логики вне контроллера Продемонстрировать работающий сервис
с реализацией логики вне контроллера
# Алгоритм решения задачи # Алгоритм решения задачи
- Создать пустое веб-апи сервис на основе шаблона - Создать пустое веб-апи сервис на основе шаблона

Loading…
Cancel
Save