Skip to content

Commit

Permalink
Add new crud
Browse files Browse the repository at this point in the history
  • Loading branch information
DE127 committed Apr 5, 2024
1 parent 7c7dee3 commit 221c96c
Show file tree
Hide file tree
Showing 20 changed files with 1,240 additions and 6 deletions.
162 changes: 162 additions & 0 deletions web_aps.net/Controllers/BannersController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using web_aps.net.Models;

namespace web_aps.net.Controllers
{
public class BannersController : Controller
{
private readonly BDKSo3Context _context;

public BannersController(BDKSo3Context context)
{
_context = context;
}

// GET: Banners
public async Task<IActionResult> Index()
{
return _context.Banners != null ?
View(await _context.Banners.ToListAsync()) :
Problem("Entity set 'BDKSo3Context.Banners' is null.");
}

// GET: Banners/Details/5
public async Task<IActionResult> Details(int? id)
{
if (id == null || _context.Banners == null)
{
return NotFound();
}

var banner = await _context.Banners
.FirstOrDefaultAsync(m => m.Id == id);
if (banner == null)
{
return NotFound();
}

return View(banner);
}

// GET: Banners/Create
public IActionResult Create()
{
return View();
}

// POST: Banners/Create
// To protect from overposting attacks, 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,Name,Status,Prioty,Image,Description")] Banner banner)
{
if (ModelState.IsValid)
{
_context.Add(banner);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(banner);
}

// GET: Banners/Edit/5
public async Task<IActionResult> Edit(int? id)
{
if (id == null || _context.Banners == null)
{
return NotFound();
}

var banner = await _context.Banners.FindAsync(id);
if (banner == null)
{
return NotFound();
}
return View(banner);
}

// POST: Banners/Edit/5
// To protect from overposting attacks, 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,Name,Status,Prioty,Image,Description")] Banner banner)
{
if (id != banner.Id)
{
return NotFound();
}

if (ModelState.IsValid)
{
try
{
_context.Update(banner);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!BannerExists(banner.Id))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
return View(banner);
}

// GET: Banners/Delete/5
public async Task<IActionResult> Delete(int? id)
{
if (id == null || _context.Banners == null)
{
return NotFound();
}

var banner = await _context.Banners
.FirstOrDefaultAsync(m => m.Id == id);
if (banner == null)
{
return NotFound();
}

return View(banner);
}

// POST: Banners/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
if (_context.Banners == null)
{
return Problem("Entity set 'BDKSo3Context.Banners' is null.");
}
var banner = await _context.Banners.FindAsync(id);
if (banner != null)
{
_context.Banners.Remove(banner);
}

await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}

private bool BannerExists(int id)
{
return (_context.Banners?.Any(e => e.Id == id)).GetValueOrDefault();
}
}
}
162 changes: 162 additions & 0 deletions web_aps.net/Controllers/BlogsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using web_aps.net.Models;

namespace web_aps.net.Controllers
{
public class BlogsController : Controller
{
private readonly BDKSo3Context _context;

public BlogsController(BDKSo3Context context)
{
_context = context;
}

// GET: Blogs
public async Task<IActionResult> Index()
{
return _context.Blogs != null ?
View(await _context.Blogs.ToListAsync()) :
Problem("Entity set 'BDKSo3Context.Blogs' is null.");
}

// GET: Blogs/Details/5
public async Task<IActionResult> Details(int? id)
{
if (id == null || _context.Blogs == null)
{
return NotFound();
}

var blog = await _context.Blogs
.FirstOrDefaultAsync(m => m.Id == id);
if (blog == null)
{
return NotFound();
}

return View(blog);
}

// GET: Blogs/Create
public IActionResult Create()
{
return View();
}

// POST: Blogs/Create
// To protect from overposting attacks, 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,Name,Status,CreatedDate,Image,Description")] Blog blog)
{
if (ModelState.IsValid)
{
_context.Add(blog);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(blog);
}

// GET: Blogs/Edit/5
public async Task<IActionResult> Edit(int? id)
{
if (id == null || _context.Blogs == null)
{
return NotFound();
}

var blog = await _context.Blogs.FindAsync(id);
if (blog == null)
{
return NotFound();
}
return View(blog);
}

// POST: Blogs/Edit/5
// To protect from overposting attacks, 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,Name,Status,CreatedDate,Image,Description")] Blog blog)
{
if (id != blog.Id)
{
return NotFound();
}

if (ModelState.IsValid)
{
try
{
_context.Update(blog);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!BlogExists(blog.Id))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
return View(blog);
}

// GET: Blogs/Delete/5
public async Task<IActionResult> Delete(int? id)
{
if (id == null || _context.Blogs == null)
{
return NotFound();
}

var blog = await _context.Blogs
.FirstOrDefaultAsync(m => m.Id == id);
if (blog == null)
{
return NotFound();
}

return View(blog);
}

// POST: Blogs/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
if (_context.Blogs == null)
{
return Problem("Entity set 'BDKSo3Context.Blogs' is null.");
}
var blog = await _context.Blogs.FindAsync(id);
if (blog != null)
{
_context.Blogs.Remove(blog);
}

await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}

private bool BlogExists(int id)
{
return (_context.Blogs?.Any(e => e.Id == id)).GetValueOrDefault();
}
}
}

0 comments on commit 221c96c

Please sign in to comment.