Skip to content

Commit 6b6c816

Browse files
committedJun 18, 2020
Initial commit
0 parents  commit 6b6c816

File tree

184 files changed

+16829
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+16829
-0
lines changed
 

‎.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

‎Controllers/KategorisController.cs

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Http;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.EntityFrameworkCore;
8+
using UdviklingEksamen.Data;
9+
using UdviklingEksamen.Models;
10+
11+
namespace UdviklingEksamen.Controllers
12+
{
13+
[Route("api/[controller]")]
14+
[ApiController]
15+
public class KategorisController : ControllerBase
16+
{
17+
private readonly ProduktContext _context;
18+
19+
public KategorisController(ProduktContext context)
20+
{
21+
_context = context;
22+
}
23+
24+
// GET: api/Kategoris
25+
[HttpGet]
26+
public async Task<ActionResult<IEnumerable<Kategori>>> GetKategoris()
27+
{
28+
return await _context.Kategoris.ToListAsync();
29+
}
30+
31+
// GET: api/Kategoris/5
32+
[HttpGet("{id}")]
33+
public async Task<ActionResult<Kategori>> GetKategori(int id)
34+
{
35+
var kategori = await _context.Kategoris.FindAsync(id);
36+
37+
if (kategori == null)
38+
{
39+
return NotFound();
40+
}
41+
42+
return kategori;
43+
}
44+
45+
// PUT: api/Kategoris/5
46+
// To protect from overposting attacks, enable the specific properties you want to bind to, for
47+
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
48+
[HttpPut("{id}")]
49+
public async Task<IActionResult> PutKategori(int id, Kategori kategori)
50+
{
51+
if (id != kategori.Id)
52+
{
53+
return BadRequest();
54+
}
55+
56+
_context.Entry(kategori).State = EntityState.Modified;
57+
58+
try
59+
{
60+
await _context.SaveChangesAsync();
61+
}
62+
catch (DbUpdateConcurrencyException)
63+
{
64+
if (!KategoriExists(id))
65+
{
66+
return NotFound();
67+
}
68+
else
69+
{
70+
throw;
71+
}
72+
}
73+
74+
return NoContent();
75+
}
76+
77+
// POST: api/Kategoris
78+
// To protect from overposting attacks, enable the specific properties you want to bind to, for
79+
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
80+
[HttpPost]
81+
public async Task<ActionResult<Kategori>> PostKategori(Kategori kategori)
82+
{
83+
_context.Kategoris.Add(kategori);
84+
await _context.SaveChangesAsync();
85+
86+
return CreatedAtAction("GetKategori", new { id = kategori.Id }, kategori);
87+
}
88+
89+
// DELETE: api/Kategoris/5
90+
[HttpDelete("{id}")]
91+
public async Task<ActionResult<Kategori>> DeleteKategori(int id)
92+
{
93+
var kategori = await _context.Kategoris.FindAsync(id);
94+
if (kategori == null)
95+
{
96+
return NotFound();
97+
}
98+
99+
_context.Kategoris.Remove(kategori);
100+
await _context.SaveChangesAsync();
101+
102+
return kategori;
103+
}
104+
105+
private bool KategoriExists(int id)
106+
{
107+
return _context.Kategoris.Any(e => e.Id == id);
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)
Please sign in to comment.