Drugi
This commit is contained in:
62
ZpcBulletinBoard/Pages/Boards/AddEdit.cshtml
Normal file
62
ZpcBulletinBoard/Pages/Boards/AddEdit.cshtml
Normal file
@@ -0,0 +1,62 @@
|
||||
@page "{handler?}"
|
||||
@model ZpcBulletinBoard.Pages.Boards.AddEditModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Edit board";
|
||||
Layout = "~/Pages/Shared/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<!-- Editor -->
|
||||
|
||||
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
|
||||
<span>
|
||||
<span class="text-muted font-weight-light">Nalog /</span>
|
||||
@if (Model.Board.IdBulletinBoard > 0)
|
||||
{
|
||||
<span>Urejanje</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Vnos</span>
|
||||
}
|
||||
</span>
|
||||
</h4>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<form method="post">
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
<input type="hidden" asp-for="Board.IdBulletinBoard" />
|
||||
<input type="hidden" asp-for="Board.Guid" />
|
||||
<div class="form-group">
|
||||
<label asp-for="Board.Name" class="control-label"></label>
|
||||
<input asp-for="Board.Name" class="form-control" />
|
||||
<span asp-validation-for="Board.Name" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Board.Ratio" class="control-label"></label>
|
||||
<select asp-for="Board.Ratio" class="form-control" asp-items="Html.GetEnumSelectList<Models.Editor.BulletinBoard.RatioEnum>()"></select>
|
||||
<span asp-validation-for="Board.Ratio" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="submit" value="Save" class="btn btn-primary" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
|
||||
|
||||
@section Scripts {
|
||||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
|
||||
|
||||
<!-- Editor -->
|
||||
|
||||
<script>
|
||||
|
||||
</script>
|
||||
}
|
||||
110
ZpcBulletinBoard/Pages/Boards/AddEdit.cshtml.cs
Normal file
110
ZpcBulletinBoard/Pages/Boards/AddEdit.cshtml.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ZpcBulletinBoard.Data;
|
||||
using ZpcBulletinBoard.Models;
|
||||
using ZpcBulletinBoard.Models.Editor;
|
||||
|
||||
namespace ZpcBulletinBoard.Pages.Boards
|
||||
|
||||
{
|
||||
//[Authorize(Roles = "Administrator,TransportThingUser,InvoicingUser")]
|
||||
public class AddEditModel(ApplicationDbContext context)
|
||||
//public class AddEditModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager)
|
||||
: PageModel
|
||||
{
|
||||
[BindProperty]
|
||||
public BulletinBoard Board { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(Guid? guid)
|
||||
{
|
||||
//var user = userManager.GetUserAsync(User).Result;
|
||||
|
||||
if (guid == null)
|
||||
{
|
||||
Board = new BulletinBoard
|
||||
{
|
||||
Ratio = BulletinBoard.RatioEnum.Ratio16To9,
|
||||
Guid = Guid.NewGuid(),
|
||||
Notes = new List<Note>()
|
||||
};
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
var tmpBoard = await context.BulletinBoards.Include(x => x.Notes)
|
||||
.FirstOrDefaultAsync(m => m.Guid == guid);
|
||||
|
||||
|
||||
if (tmpBoard == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
Board = tmpBoard;
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("OnPost");
|
||||
|
||||
//var user = userManager.GetUserAsync(User).Result;
|
||||
//Board.Notes = new List<Note>();
|
||||
//if (!ModelState.IsValid)
|
||||
//{
|
||||
// System.Diagnostics.Debug.WriteLine(string.Join(",", ModelState.Where(a => a.Value.Errors.Count > 0)
|
||||
// .Select(b => $"{b.Key} {b.Value.Errors}")));
|
||||
// return Page();
|
||||
//}
|
||||
|
||||
if (Board.IdBulletinBoard > 0)
|
||||
{
|
||||
context.Attach(Board).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!BoardExists(Board.IdBulletinBoard))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return RedirectToPage("./Index");
|
||||
}
|
||||
|
||||
// OrderNumber and OrderYear
|
||||
|
||||
context.BulletinBoards.Add(Board);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
|
||||
return RedirectToPage("./Index");
|
||||
}
|
||||
|
||||
|
||||
private bool BoardExists(int id)
|
||||
{
|
||||
return context.BulletinBoards.Any(e => e.IdBulletinBoard == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
69
ZpcBulletinBoard/Pages/Boards/Index.cshtml
Normal file
69
ZpcBulletinBoard/Pages/Boards/Index.cshtml
Normal file
@@ -0,0 +1,69 @@
|
||||
@page
|
||||
@model ZpcBulletinBoard.Pages.Boards.IndexModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Oglasne deske - Pregled";
|
||||
Layout = "~/Pages/Shared/_Layout.cshtml";
|
||||
}
|
||||
|
||||
@section Styles {
|
||||
<link rel="stylesheet" href="~/vendor/libs/bootstrap-material-datetimepicker/bootstrap-material-datetimepicker.css">
|
||||
|
||||
<style type="text/css">
|
||||
.table > tbody > tr > td:nth-child(2),
|
||||
.table > thead > tr > th:nth-child(2),
|
||||
.table > tbody > tr > td:nth-child(3),
|
||||
.table > thead > tr > th:nth-child(3) {
|
||||
width: 100px
|
||||
}
|
||||
</style>
|
||||
}
|
||||
|
||||
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
|
||||
<span>
|
||||
<span class="text-muted font-weight-light">
|
||||
<i>Oglasne deske</i>
|
||||
/</span> Pregled
|
||||
</span>
|
||||
</h4>
|
||||
|
||||
<div class="card">
|
||||
<h6 class="card-header">
|
||||
Seznam oglasnih desk
|
||||
</h6>
|
||||
<table class="table card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Boards[0].Name)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Boards[0].Ratio)
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model.Boards)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Name)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Ratio)
|
||||
</td>
|
||||
<td>
|
||||
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" asp-page="AddEdit" asp-route-guid="@item.Guid" data-toggle="tooltip" data-placement="top" title="Urejanje" data-state="secondary"><i class="fas fa-pencil-alt"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="card-footer py-3 text-right">
|
||||
<a asp-page="AddEdit" class="btn btn-primary">Dodaj novo</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
}
|
||||
24
ZpcBulletinBoard/Pages/Boards/Index.cshtml.cs
Normal file
24
ZpcBulletinBoard/Pages/Boards/Index.cshtml.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using ZpcBulletinBoard.Data;
|
||||
using ZpcBulletinBoard.Models.Editor;
|
||||
|
||||
namespace ZpcBulletinBoard.Pages.Boards
|
||||
{
|
||||
//[Authorize]
|
||||
public class IndexModel(ApplicationDbContext context) : PageModel
|
||||
{
|
||||
public IList<BulletinBoard> Boards { get;set; }
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
Boards = await context.BulletinBoards.ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user