Browse Source

update - KatalogController kopiert, zu InventarController umgeschrieben

InventarDavid
David Renner 2 years ago
parent
commit
7f5ca580c6
  1. BIN
      .vs/BuecherwurmAPI/v16/.suo
  2. BIN
      .vs/slnx.sqlite
  3. 72
      Controllers/InventarController.cs
  4. 39
      Controllers/WeatherForecastController.cs
  5. 15
      WeatherForecast.cs

BIN
.vs/BuecherwurmAPI/v16/.suo

Binary file not shown.

BIN
.vs/slnx.sqlite

Binary file not shown.

72
Controllers/InventarController.cs

@ -0,0 +1,72 @@
using System.Collections.Generic;
using BuecherwurmAPI.Models;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using BuecherwurmAPI.Data;
namespace BuecherwurmAPI.Controllers
{
[Route("inventar")]
[ApiController]
public class InventarController : ControllerBase
{
private readonly IBookRepo _repository;
public InventarController(IBookRepo repository)
{
_repository = repository;
}
// GET Inventar
[HttpGet]
public ActionResult<IEnumerable<>> GetAllCopies()
{
var copies = _repository.GetAllCopies();
return Ok(copies);
}
// POST Inventar
[HttpPost]
public ActionResult<IEnumerable<Book>> NeuesExemplar(Copy copy)
{
return Ok(new Copy
{
CopyId = copy.CopyId,
ProductId = book.ProductId,
LendTime = copy.LendTime,
LendType = copy.LendType
});
}
// GET Inventar/{id}
[HttpGet("{id}", Name = "GetCopyByID")]
public ActionResult<IEnumerable<Copy>> GetCopyByID(int id)
{
var copy = _repository.GetCopyById(id);
if (copy != null)
{
return Ok(copy);
}
return NoContent();
}
// DELETE katalog/{id}
/*[HttpDelete("id")]
public ActionResult<IEnumerable<Book>> BuchEntfernen(int id)
{
var book = _repository.GetBookById(id);
if (book == null)
{
return NotFound();
}
_repository.BuchEntfernen(book);
return NoContent();
}*/
}
}

39
Controllers/WeatherForecastController.cs

@ -1,39 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace BuecherwurmAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}
}

15
WeatherForecast.cs

@ -1,15 +0,0 @@
using System;
namespace BuecherwurmAPI
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string Summary { get; set; }
}
}
Loading…
Cancel
Save