Banner CURD operation completed
This commit is contained in:
parent
4a65418344
commit
3b98fd109f
6 changed files with 387 additions and 60 deletions
|
|
@ -60,11 +60,96 @@ namespace Web.Areas.Admin.Controllers
|
||||||
await _banner.Add(banner);
|
await _banner.Add(banner);
|
||||||
|
|
||||||
await _banner.commitAsync();
|
await _banner.commitAsync();
|
||||||
|
TempData["Success"] = "Banner created successfully";
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
return RedirectToAction(nameof(Index));
|
||||||
|
|
||||||
}
|
}
|
||||||
return View(viewmodel);
|
return View(viewmodel);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Edit(int id)
|
||||||
|
{
|
||||||
|
var bannerFromdb = _banner.GetBannerById(id);
|
||||||
|
|
||||||
|
var viewmodel = new BannerViewModel
|
||||||
|
{
|
||||||
|
Id=bannerFromdb.Id,
|
||||||
|
Title=bannerFromdb.Title,
|
||||||
|
Description=bannerFromdb.Description,
|
||||||
|
Content=bannerFromdb.Content,
|
||||||
|
ImageUrl=bannerFromdb.ImageUrl,
|
||||||
|
LinkUrl=bannerFromdb.ImageUrl,
|
||||||
|
};
|
||||||
|
|
||||||
|
return View(viewmodel);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<IActionResult> Edit(BannerViewModel viewmodel)
|
||||||
|
{
|
||||||
|
if(ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var banner = _banner.GetBannerById(viewmodel.Id);
|
||||||
|
|
||||||
|
banner.Title = viewmodel.Title;
|
||||||
|
banner.Content = viewmodel.Content;
|
||||||
|
banner.Description = viewmodel.Description;
|
||||||
|
banner.LinkUrl = viewmodel.LinkUrl;
|
||||||
|
banner.ImageUrl = viewmodel.ImageUrl;
|
||||||
|
|
||||||
|
_banner.Update(banner);
|
||||||
|
|
||||||
|
await _banner.commitAsync();
|
||||||
|
TempData["Success"] = "Banner updated successfully";
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return View(viewmodel);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Delete(int id)
|
||||||
|
{
|
||||||
|
var bannerFromDb = _banner.GetBannerById(id);
|
||||||
|
|
||||||
|
var viewmodel = new BannerViewModel
|
||||||
|
{
|
||||||
|
Id=bannerFromDb.Id,
|
||||||
|
Title=bannerFromDb.Title,
|
||||||
|
Description=bannerFromDb.Description,
|
||||||
|
Content=bannerFromDb.Content,
|
||||||
|
ImageUrl=bannerFromDb.ImageUrl,
|
||||||
|
LinkUrl=bannerFromDb.ImageUrl,
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
return View(viewmodel);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[ActionName("Delete")]
|
||||||
|
public async Task<IActionResult> DeleteConfirm(int id)
|
||||||
|
{
|
||||||
|
|
||||||
|
//var banner = _banner.GetBannerById(id);
|
||||||
|
|
||||||
|
_banner.Delete(id);
|
||||||
|
|
||||||
|
await _banner.commitAsync();
|
||||||
|
TempData["Success"] = "Banner deleted successfully";
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
118
Web/Areas/Admin/Views/Banner/Delete.cshtml
Normal file
118
Web/Areas/Admin/Views/Banner/Delete.cshtml
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
@model BannerViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Delete";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
<div class="container mt-4">
|
||||||
|
<div class="card justify-content-center">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Delete banner</h5>
|
||||||
|
<h6 class="text-danger">Are you sure you want to delete the <span class="badge bg-danger">@Model.Title</span></h6>
|
||||||
|
|
||||||
|
<div class="row ">
|
||||||
|
<!-- 12 columns for textboxes -->
|
||||||
|
|
||||||
|
<form asp-action="Delete">
|
||||||
|
<div asp-validation-summary="All" class="text-danger"></div>
|
||||||
|
|
||||||
|
<div class="mb-3 col-12">
|
||||||
|
<label asp-for="Title" class="control-label"></label>
|
||||||
|
<input asp-for="Title" class="form-control" disabled/>
|
||||||
|
<span asp-validation-for="Title" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 col-12">
|
||||||
|
<label asp-for="Description" class="control-label"></label>
|
||||||
|
<input asp-for="Description" class="form-control" disabled />
|
||||||
|
<span asp-validation-for="Description" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 col-12">
|
||||||
|
<label asp-for="Content" class="control-label"></label>
|
||||||
|
<textarea asp-for="Content" disabled></textarea>
|
||||||
|
<span asp-validation-for="Content" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 col-12">
|
||||||
|
<label asp-for="LinkUrl" class="control-label"></label>
|
||||||
|
<input asp-for="LinkUrl" class="form-control" disabled />
|
||||||
|
<span asp-validation-for="LinkUrl" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 col-12">
|
||||||
|
<label asp-for="ImageUrl" class="control-label"></label>
|
||||||
|
<input asp-for="ImageUrl" class="form-control" disabled />
|
||||||
|
<span asp-validation-for="ImageUrl" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<input type="submit" value="Delete" class="btn btn-outline-primary" /> | <a asp-action="Index" class="btn btn-primary">Back to list</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/ckeditor/4.11.4/ckeditor.js"></script>
|
||||||
|
<script>
|
||||||
|
CKEDITOR.replace("Content");
|
||||||
|
</script>
|
||||||
|
@{
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@* <div>
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
<dl class="row">
|
||||||
|
<dt class = "col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.Id)
|
||||||
|
</dt>
|
||||||
|
<dd class = "col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.Id)
|
||||||
|
</dd>
|
||||||
|
<dt class = "col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.Title)
|
||||||
|
</dt>
|
||||||
|
<dd class = "col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.Title)
|
||||||
|
</dd>
|
||||||
|
<dt class = "col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.Description)
|
||||||
|
</dt>
|
||||||
|
<dd class = "col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.Description)
|
||||||
|
</dd>
|
||||||
|
<dt class = "col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.Content)
|
||||||
|
</dt>
|
||||||
|
<dd class = "col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.Content)
|
||||||
|
</dd>
|
||||||
|
<dt class = "col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.LinkUrl)
|
||||||
|
</dt>
|
||||||
|
<dd class = "col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.LinkUrl)
|
||||||
|
</dd>
|
||||||
|
<dt class = "col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.ImageUrl)
|
||||||
|
</dt>
|
||||||
|
<dd class = "col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.ImageUrl)
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<form asp-action="Delete">
|
||||||
|
<input type="submit" value="Delete" class="btn btn-danger" /> |
|
||||||
|
<a asp-action="Index">Back to List</a>
|
||||||
|
</form>
|
||||||
|
</div> *@
|
||||||
109
Web/Areas/Admin/Views/Banner/Edit.cshtml
Normal file
109
Web/Areas/Admin/Views/Banner/Edit.cshtml
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
@model BannerViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Edit";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="container mt-4">
|
||||||
|
<div class="card justify-content-center">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Update banner</h5>
|
||||||
|
|
||||||
|
<div class="row ">
|
||||||
|
<!-- 12 columns for textboxes -->
|
||||||
|
|
||||||
|
<form asp-action="Edit">
|
||||||
|
<div asp-validation-summary="All" class="text-danger"></div>
|
||||||
|
|
||||||
|
<div class="mb-3 col-12">
|
||||||
|
<label asp-for="Title" class="control-label"></label>
|
||||||
|
<input asp-for="Title" class="form-control" />
|
||||||
|
<span asp-validation-for="Title" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 col-12">
|
||||||
|
<label asp-for="Description" class="control-label"></label>
|
||||||
|
<input asp-for="Description" class="form-control" />
|
||||||
|
<span asp-validation-for="Description" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 col-12">
|
||||||
|
<label asp-for="Content" class="control-label"></label>
|
||||||
|
<textarea asp-for="Content"></textarea>
|
||||||
|
<span asp-validation-for="Content" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 col-12">
|
||||||
|
<label asp-for="LinkUrl" class="control-label"></label>
|
||||||
|
<input asp-for="LinkUrl" class="form-control" />
|
||||||
|
<span asp-validation-for="LinkUrl" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 col-12">
|
||||||
|
<label asp-for="ImageUrl" class="control-label"></label>
|
||||||
|
<input asp-for="ImageUrl" class="form-control" />
|
||||||
|
<span asp-validation-for="ImageUrl" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<input type="submit" value="Update" class="btn btn-outline-primary" /> | <a asp-action="Index" class="btn btn-primary">Back to list</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/ckeditor/4.11.4/ckeditor.js"></script>
|
||||||
|
<script>
|
||||||
|
CKEDITOR.replace("Content");
|
||||||
|
</script>
|
||||||
|
@{
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
@* <div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<form asp-action="Edit">
|
||||||
|
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Id" class="control-label"></label>
|
||||||
|
<input asp-for="Id" class="form-control" />
|
||||||
|
<span asp-validation-for="Id" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Title" class="control-label"></label>
|
||||||
|
<input asp-for="Title" class="form-control" />
|
||||||
|
<span asp-validation-for="Title" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Description" class="control-label"></label>
|
||||||
|
<input asp-for="Description" class="form-control" />
|
||||||
|
<span asp-validation-for="Description" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="Content" class="control-label"></label>
|
||||||
|
<input asp-for="Content" class="form-control" />
|
||||||
|
<span asp-validation-for="Content" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="LinkUrl" class="control-label"></label>
|
||||||
|
<input asp-for="LinkUrl" class="form-control" />
|
||||||
|
<span asp-validation-for="LinkUrl" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label asp-for="ImageUrl" class="control-label"></label>
|
||||||
|
<input asp-for="ImageUrl" class="form-control" />
|
||||||
|
<span asp-validation-for="ImageUrl" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="submit" value="Save" class="btn btn-primary" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div> *@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -4,64 +4,63 @@
|
||||||
ViewData["Title"] = "Index";
|
ViewData["Title"] = "Index";
|
||||||
}
|
}
|
||||||
|
|
||||||
<h1>Index</h1>
|
|
||||||
|
|
||||||
<p>
|
<div class="container">
|
||||||
|
|
||||||
|
<partial name="_Notification"/>
|
||||||
|
|
||||||
|
<div class="card text-white bg-info mb-3 justify-content-center">
|
||||||
|
<div class="card-header">Banners</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h4 class="card-title">Banner list</h4>
|
||||||
|
<p>
|
||||||
<a asp-action="Create" class="btn btn-primary">Create New</a>
|
<a asp-action="Create" class="btn btn-primary">Create New</a>
|
||||||
</p>
|
</p>
|
||||||
<table class="table">
|
|
||||||
|
<table class="table table-hover table-responsive">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.Id)
|
<th scope="col">Id</th>
|
||||||
</th>
|
<th scope="col">Title</th>
|
||||||
<th>
|
<th scope="col">Description</th>
|
||||||
@Html.DisplayNameFor(model => model.Title)
|
<th scope="col">Link Url</th>
|
||||||
</th>
|
<th scope="col" class="d-flex justify-content-end">Action</th>
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.Description)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.Content)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.LinkUrl)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.ImageUrl)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
Action
|
|
||||||
</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach (var item in Model) {
|
@foreach (var item in Model)
|
||||||
<tr>
|
{
|
||||||
<td>
|
<tr class="table-secondary">
|
||||||
@Html.DisplayFor(modelItem => item.Id)
|
|
||||||
</td>
|
<td>@item.Id</td>
|
||||||
<td>
|
<td> <span class="badge bg-primary">@item.Title</span></td>
|
||||||
@Html.DisplayFor(modelItem => item.Title)
|
<td>@item.Description</td>
|
||||||
</td>
|
<td>@item.LinkUrl</td>
|
||||||
<td>
|
<td class="d-flex justify-content-end">
|
||||||
@Html.DisplayFor(modelItem => item.Description)
|
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger"><i class="bi bi-trash"></i> Delete</a> |
|
||||||
</td>
|
<a asp-action="Edit" asp-route-id="@item.Id" class="btn btn-warning"><i class="bi bi-pencil-square"></i> Edit</a>
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.Content)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.LinkUrl)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.ImageUrl)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
|
|
||||||
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
|
|
||||||
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
|
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
|
||||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||||
<link rel="stylesheet" href="~/Web.styles.css" asp-append-version="true" />
|
<link rel="stylesheet" href="~/Web.styles.css" asp-append-version="true" />
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||||
|
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css" />
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
||||||
14
Web/Areas/Admin/Views/Shared/_Notification.cshtml
Normal file
14
Web/Areas/Admin/Views/Shared/_Notification.cshtml
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
@if (TempData["Success"] != null)
|
||||||
|
{
|
||||||
|
<script src="/lib/jquery/dist/jquery.min.js"></script>
|
||||||
|
|
||||||
|
<script src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
toastr.success('@TempData["Success"]')
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue