Skip to content

Commit

Permalink
add sample files for horusec-engine
Browse files Browse the repository at this point in the history
Co-authored-by: Matheus Alcantara <[email protected]>
  • Loading branch information
matheusalcantarazup committed Sep 16, 2021
1 parent 39f4591 commit 36c5c9b
Show file tree
Hide file tree
Showing 13 changed files with 51,118 additions and 0 deletions.
Binary file added samples/PetsController.utf16be.cs
Binary file not shown.
Binary file added samples/PetsController.utf16bebom.cs
Binary file not shown.
Binary file added samples/PetsController.utf16le.cs
Binary file not shown.
Binary file added samples/PetsController.utf16lebom.cs
Binary file not shown.
66 changes: 66 additions & 0 deletions samples/PetsController.utf8.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Mime;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WebApiSample.Models;

namespace WebApiSample.Controllers
{
#region snippet_Inherit
[Produces(MediaTypeNames.Application.Json)]
[Route("[controller]")]
public class PetsController : MyControllerBase
#endregion
{
private static readonly List<Pet> _petsInMemoryStore = new List<Pet>();

public PetsController()
{
if (_petsInMemoryStore.Count == 0)
{
_petsInMemoryStore.Add(
new Pet
{
Breed = "Collie",
Id = 1,
Name = "Fido",
PetType = PetType.Dog
});
}
}

[HttpGet]
public ActionResult<List<Pet>> GetAll() => _petsInMemoryStore;

[HttpGet("{id}")]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult<Pet> GetById(int id)
{
var pet = _petsInMemoryStore.FirstOrDefault(p => p.Id == id);

#region snippet_ProblemDetailsStatusCode
if (pet == null)
{
return NotFound();
}
#endregion

return pet;
}

#region snippet_400And201
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public ActionResult<Pet> Create(Pet pet)
{
pet.Id = _petsInMemoryStore.Any() ?
_petsInMemoryStore.Max(p => p.Id) + 1 : 1;
_petsInMemoryStore.Add(pet);

return CreatedAtAction(nameof(GetById), new { id = pet.Id }, pet);
}
#endregion
}
}
66 changes: 66 additions & 0 deletions samples/PetsController.utf8bom.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Mime;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WebApiSample.Models;

namespace WebApiSample.Controllers
{
#region snippet_Inherit
[Produces(MediaTypeNames.Application.Json)]
[Route("[controller]")]
public class PetsController : MyControllerBase
#endregion
{
private static readonly List<Pet> _petsInMemoryStore = new List<Pet>();

public PetsController()
{
if (_petsInMemoryStore.Count == 0)
{
_petsInMemoryStore.Add(
new Pet
{
Breed = "Collie",
Id = 1,
Name = "Fido",
PetType = PetType.Dog
});
}
}

[HttpGet]
public ActionResult<List<Pet>> GetAll() => _petsInMemoryStore;

[HttpGet("{id}")]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult<Pet> GetById(int id)
{
var pet = _petsInMemoryStore.FirstOrDefault(p => p.Id == id);

#region snippet_ProblemDetailsStatusCode
if (pet == null)
{
return NotFound();
}
#endregion

return pet;
}

#region snippet_400And201
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public ActionResult<Pet> Create(Pet pet)
{
pet.Id = _petsInMemoryStore.Any() ?
_petsInMemoryStore.Max(p => p.Id) + 1 : 1;
_petsInMemoryStore.Add(pet);

return CreatedAtAction(nameof(GetById), new { id = pet.Id }, pet);
}
#endregion
}
}
Loading

0 comments on commit 36c5c9b

Please sign in to comment.