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