Do not allow news to be edited or created manually.

This commit is contained in:
2019-05-19 00:01:35 +01:00
parent c93e29b181
commit 9e3c0e7ea7
7 changed files with 9 additions and 315 deletions

View File

@@ -49,78 +49,8 @@ namespace cicm_web.Areas.Admin.Controllers
}
// GET: Admin/News
public async Task<IActionResult> Index() => View(await _context.News.ToListAsync());
// GET: Admin/News/Details/5
public async Task<IActionResult> Details(int? id)
{
if(id == null) return NotFound();
News news = await _context.News.FirstOrDefaultAsync(m => m.Id == id);
if(news == null) return NotFound();
return View(news);
}
// GET: Admin/News/Create
public IActionResult Create() => View();
// POST: Admin/News/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Date,Type,AddedId")] News news)
{
if(ModelState.IsValid)
{
_context.Add(news);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(news);
}
// GET: Admin/News/Edit/5
public async Task<IActionResult> Edit(int? id)
{
if(id == null) return NotFound();
News news = await _context.News.FindAsync(id);
if(news == null) return NotFound();
return View(news);
}
// POST: Admin/News/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, [Bind("Id,Date,Type,AddedId")] News news)
{
if(id != news.Id) return NotFound();
if(ModelState.IsValid)
{
try
{
_context.Update(news);
await _context.SaveChangesAsync();
}
catch(DbUpdateConcurrencyException)
{
if(!NewsExists(news.Id)) return NotFound();
throw;
}
return RedirectToAction(nameof(Index));
}
return View(news);
}
public async Task<IActionResult> Index() =>
View(await _context.News.OrderByDescending(n => n.Date).ToListAsync());
// GET: Admin/News/Delete/5
public async Task<IActionResult> Delete(int? id)