chore: dbfake --> real db in controllers
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a0cab2d46f
commit
1bb9a07bfa
|
@ -3,10 +3,11 @@ using System.Linq;
|
|||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Internal;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using pwt_0x01_ng.Models;
|
||||
using pwt_0x01_ng.Models.Dbfake;
|
||||
using pwt_0x01_ng.Models.Database;
|
||||
|
||||
namespace pwt_0x01_ng.Areas.Admin.Controllers
|
||||
{
|
||||
|
@ -14,17 +15,18 @@ namespace pwt_0x01_ng.Areas.Admin.Controllers
|
|||
public class CarouselController : Controller
|
||||
{
|
||||
IWebHostEnvironment hosting_env;
|
||||
private IList<Carousel> Carousels = Dbfake.Carousels;
|
||||
readonly DBContext dbctx;
|
||||
|
||||
public CarouselController(IWebHostEnvironment hosting_env){
|
||||
public CarouselController(DBContext dbctx, IWebHostEnvironment hosting_env){
|
||||
this.dbctx = dbctx;
|
||||
this.hosting_env = hosting_env;
|
||||
}
|
||||
|
||||
// GET
|
||||
public IActionResult Select()
|
||||
public async Task <IActionResult> Select()
|
||||
{
|
||||
CarouselViewModel carousel = new CarouselViewModel();
|
||||
carousel.Carousels = Carousels;
|
||||
carousel.Carousels = await dbctx.Carousel.ToListAsync();
|
||||
return View(carousel);
|
||||
}
|
||||
|
||||
|
@ -40,13 +42,14 @@ namespace pwt_0x01_ng.Areas.Admin.Controllers
|
|||
MegaUpload mega_upload = new MegaUpload(hosting_env);
|
||||
await mega_upload.DoMegaUpload(carousel);
|
||||
|
||||
Carousels.Add(carousel);
|
||||
dbctx.Carousel.Add(carousel);
|
||||
await dbctx.SaveChangesAsync();
|
||||
return RedirectToAction(nameof(Select));
|
||||
}
|
||||
|
||||
public IActionResult Edit(int id)
|
||||
{
|
||||
Carousel carousel_item = Carousels.Where(c_item => c_item.id == id).FirstOrDefault();
|
||||
Carousel carousel_item = dbctx.Carousel.Where(c_item => c_item.id == id).FirstOrDefault();
|
||||
if (carousel_item != null)
|
||||
{
|
||||
return View(carousel_item);
|
||||
|
@ -60,7 +63,7 @@ namespace pwt_0x01_ng.Areas.Admin.Controllers
|
|||
[HttpPost]
|
||||
public async Task<IActionResult> Edit(Carousel carousel)
|
||||
{
|
||||
Carousel carousel_item = Carousels.Where(c_item => c_item.id == carousel.id).FirstOrDefault();
|
||||
Carousel carousel_item = dbctx.Carousel.Where(c_item => c_item.id == carousel.id).FirstOrDefault();
|
||||
|
||||
if (carousel_item != null)
|
||||
{
|
||||
|
@ -73,6 +76,7 @@ namespace pwt_0x01_ng.Areas.Admin.Controllers
|
|||
if (await mega_upload.DoMegaUpload(carousel)){
|
||||
carousel_item.ImageSrc = carousel.ImageSrc;
|
||||
}
|
||||
await dbctx.SaveChangesAsync();
|
||||
return RedirectToAction(nameof(Select));
|
||||
}
|
||||
else
|
||||
|
@ -81,12 +85,13 @@ namespace pwt_0x01_ng.Areas.Admin.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
public IActionResult Delete(int id)
|
||||
public async Task <IActionResult> Delete(int id)
|
||||
{
|
||||
Carousel carousel_item = Carousels.Where(c_item => c_item.id == id).FirstOrDefault();
|
||||
Carousel carousel_item = dbctx.Carousel.Where(c_item => c_item.id == id).FirstOrDefault();
|
||||
if (carousel_item != null)
|
||||
{
|
||||
Carousels.Remove(carousel_item);
|
||||
dbctx.Carousel.Remove(carousel_item);
|
||||
await dbctx.SaveChangesAsync();
|
||||
return RedirectToAction(nameof(Select));
|
||||
}
|
||||
else
|
||||
|
|
|
@ -4,19 +4,23 @@ using System.Diagnostics;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using pwt_0x01_ng.Models;
|
||||
using pwt_0x01_ng.Models.Dbfake;
|
||||
using pwt_0x01_ng.Models.Database;
|
||||
|
||||
namespace pwt_0x01_ng.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private IList<Carousel> carousels = Dbfake.Carousels;
|
||||
readonly DBContext dbctx;
|
||||
public HomeController(DBContext dbctx){
|
||||
this.dbctx = dbctx;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
public async Task <IActionResult> Index()
|
||||
{
|
||||
CarouselViewModel carousel = new CarouselViewModel();
|
||||
carousel.Carousels = carousels;
|
||||
carousel.Carousels = await dbctx.Carousel.ToListAsync();
|
||||
return View(carousel);
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue