Editor povezava na db

This commit is contained in:
David Štaleker
2024-02-27 07:27:47 +01:00
parent 4df426dc10
commit e92956075f
24 changed files with 1033 additions and 47 deletions

View File

@@ -0,0 +1,36 @@
namespace ZpcBulletinBoard.Classes
{
public static class Global
{
public static T GetAttributeOfType<T>(this Enum iEnumType) where T : System.Attribute
{
var type = iEnumType.GetType();
var memberInfo = type.GetMember(iEnumType.ToString());
var atributi = memberInfo[0].GetCustomAttributes(typeof(T), false);
return (atributi.Length > 0) ? (T)atributi[0] : null;
}
public static List<(int EnumValue, T EnumAttribute)> GetEnumListClass<T>(this Type iEnumType,
bool iUseOrder = false) where T : System.Attribute
{
List<(int EnumValue, T EnumAttribute)> titleValue = new();
foreach (var tempEnumValue in Enum.GetValues(iEnumType).Cast<Enum>())
{
object tempObject = GetAttributeOfType<T>(tempEnumValue);
titleValue.Add((Convert.ToInt32(tempEnumValue), (T)tempObject));
}
return titleValue.ToList();
}
public static TAttribute GetAttribute<TAttribute>(Enum value)
where TAttribute : Attribute
{
var enumType = value.GetType();
var name = Enum.GetName(enumType, value);
return enumType.GetField(name)?.GetCustomAttributes(false).OfType<TAttribute>().SingleOrDefault();
}
}
}

View File

@@ -22,9 +22,14 @@ namespace ZpcBulletinBoard.Data
//Relacije //Relacije
modelBuilder.Entity<BulletinBoard>() modelBuilder.Entity<BulletinBoard>()
.HasMany(t => t.Notes) .HasMany(t => t.Pages)
.WithOne(t => t.BulletinBoard) .WithOne(t => t.BulletinBoard)
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<BulletinBoardPage>()
.HasMany(t => t.Notes)
.WithOne(t => t.BulletinBoardPage)
.OnDelete(DeleteBehavior.Cascade);
} }
} }
} }

View File

@@ -0,0 +1,4 @@
MYSQL_SERVER=192.168.1.12
MYSQL_USER=david
MYSQL_PASSWORD=*staleker*
MYSQL_DATABASE=ZpcBulletinBoard

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<key id="3a63e3da-2ef0-49c2-9e68-30571c991f22" version="1">
<creationDate>2024-02-27T04:54:17.6808298Z</creationDate>
<activationDate>2024-02-27T04:54:17.6419309Z</activationDate>
<expirationDate>2024-05-27T04:54:17.6419309Z</expirationDate>
<descriptor deserializerType="Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
<descriptor>
<encryption algorithm="AES_256_CBC" />
<validation algorithm="HMACSHA256" />
<masterKey p4:requiresEncryption="true" xmlns:p4="http://schemas.asp.net/2015/03/dataProtection">
<!-- Warning: the key below is in an unencrypted form. -->
<value>1ujUNFqnvXGLHSTiSV2F9ymK+Sosgl6qdy7m0M/Z9bPXyplHR9bOAgm4cy5otT3C/q5H/Qf6NnQkgUqggldGiw==</value>
</masterKey>
</descriptor>
</descriptor>
</key>

View File

@@ -0,0 +1,405 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using ZpcBulletinBoard.Data;
#nullable disable
namespace ZpcBulletinBoard.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20240227053725_3")]
partial class _3
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("ClaimType")
.HasColumnType("longtext");
b.Property<string>("ClaimValue")
.HasColumnType("longtext");
b.Property<int>("RoleId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("ClaimType")
.HasColumnType("longtext");
b.Property<string>("ClaimValue")
.HasColumnType("longtext");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("varchar(255)");
b.Property<string>("ProviderKey")
.HasColumnType("varchar(255)");
b.Property<string>("ProviderDisplayName")
.HasColumnType("longtext");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<int>", b =>
{
b.Property<int>("UserId")
.HasColumnType("int");
b.Property<int>("RoleId")
.HasColumnType("int");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>
{
b.Property<int>("UserId")
.HasColumnType("int");
b.Property<string>("LoginProvider")
.HasColumnType("varchar(255)");
b.Property<string>("Name")
.HasColumnType("varchar(255)");
b.Property<string>("Value")
.HasColumnType("longtext");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoard", b =>
{
b.Property<int>("IdBulletinBoard")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<Guid>("Guid")
.HasColumnType("char(36)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("Ratio")
.HasColumnType("int");
b.HasKey("IdBulletinBoard");
b.ToTable("BulletinBoards");
});
modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", b =>
{
b.Property<int>("IdBulletinBoardPage")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<int>("Duration")
.HasColumnType("int");
b.Property<int>("IdBulletinBoard")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.HasKey("IdBulletinBoardPage");
b.HasIndex("IdBulletinBoard");
b.ToTable("BulletinBoardPage");
});
modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.Note", b =>
{
b.Property<int>("IdNote")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("Height")
.HasColumnType("int");
b.Property<int>("IdBulletinBoardPage")
.HasColumnType("int");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("Width")
.HasColumnType("int");
b.Property<int>("X")
.HasColumnType("int");
b.Property<int>("Y")
.HasColumnType("int");
b.HasKey("IdNote");
b.HasIndex("IdBulletinBoardPage");
b.ToTable("Notes");
});
modelBuilder.Entity("ZpcBulletinBoard.Models.IdentityApplicationRole", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<bool>("Active")
.HasColumnType("tinyint(1)");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("longtext");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("varchar(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("varchar(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("ZpcBulletinBoard.Models.IdentityApplicationUser", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<int>("AccessFailedCount")
.HasColumnType("int");
b.Property<bool>("Active")
.HasColumnType("tinyint(1)");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("longtext");
b.Property<DateTime>("DateCreated")
.HasColumnType("datetime(6)");
b.Property<DateTime>("DateValidUntil")
.HasColumnType("datetime(6)");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("varchar(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("tinyint(1)");
b.Property<bool>("LockoutEnabled")
.HasColumnType("tinyint(1)");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("datetime(6)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("varchar(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("varchar(256)");
b.Property<string>("PasswordHash")
.HasColumnType("longtext");
b.Property<string>("PhoneNumber")
.HasColumnType("longtext");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("tinyint(1)");
b.Property<string>("SecurityStamp")
.HasColumnType("longtext");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("longtext");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("tinyint(1)");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("varchar(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<int>", b =>
{
b.HasOne("ZpcBulletinBoard.Models.IdentityApplicationRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<int>", b =>
{
b.HasOne("ZpcBulletinBoard.Models.IdentityApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<int>", b =>
{
b.HasOne("ZpcBulletinBoard.Models.IdentityApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<int>", b =>
{
b.HasOne("ZpcBulletinBoard.Models.IdentityApplicationRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ZpcBulletinBoard.Models.IdentityApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<int>", b =>
{
b.HasOne("ZpcBulletinBoard.Models.IdentityApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", b =>
{
b.HasOne("ZpcBulletinBoard.Models.Editor.BulletinBoard", "BulletinBoard")
.WithMany("Pages")
.HasForeignKey("IdBulletinBoard")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("BulletinBoard");
});
modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.Note", b =>
{
b.HasOne("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", "BulletinBoardPage")
.WithMany("Notes")
.HasForeignKey("IdBulletinBoardPage")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("BulletinBoardPage");
});
modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoard", b =>
{
b.Navigation("Pages");
});
modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", b =>
{
b.Navigation("Notes");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,94 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ZpcBulletinBoard.Migrations
{
/// <inheritdoc />
public partial class _3 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Notes_BulletinBoards_IdBulletinBoard",
table: "Notes");
migrationBuilder.RenameColumn(
name: "IdBulletinBoard",
table: "Notes",
newName: "IdBulletinBoardPage");
migrationBuilder.RenameIndex(
name: "IX_Notes_IdBulletinBoard",
table: "Notes",
newName: "IX_Notes_IdBulletinBoardPage");
migrationBuilder.CreateTable(
name: "BulletinBoardPage",
columns: table => new
{
IdBulletinBoardPage = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
IdBulletinBoard = table.Column<int>(type: "int", nullable: false),
Name = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Duration = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_BulletinBoardPage", x => x.IdBulletinBoardPage);
table.ForeignKey(
name: "FK_BulletinBoardPage_BulletinBoards_IdBulletinBoard",
column: x => x.IdBulletinBoard,
principalTable: "BulletinBoards",
principalColumn: "IdBulletinBoard",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_BulletinBoardPage_IdBulletinBoard",
table: "BulletinBoardPage",
column: "IdBulletinBoard");
migrationBuilder.AddForeignKey(
name: "FK_Notes_BulletinBoardPage_IdBulletinBoardPage",
table: "Notes",
column: "IdBulletinBoardPage",
principalTable: "BulletinBoardPage",
principalColumn: "IdBulletinBoardPage",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Notes_BulletinBoardPage_IdBulletinBoardPage",
table: "Notes");
migrationBuilder.DropTable(
name: "BulletinBoardPage");
migrationBuilder.RenameColumn(
name: "IdBulletinBoardPage",
table: "Notes",
newName: "IdBulletinBoard");
migrationBuilder.RenameIndex(
name: "IX_Notes_IdBulletinBoardPage",
table: "Notes",
newName: "IX_Notes_IdBulletinBoard");
migrationBuilder.AddForeignKey(
name: "FK_Notes_BulletinBoards_IdBulletinBoard",
table: "Notes",
column: "IdBulletinBoard",
principalTable: "BulletinBoards",
principalColumn: "IdBulletinBoard",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@@ -139,6 +139,29 @@ namespace ZpcBulletinBoard.Migrations
b.ToTable("BulletinBoards"); b.ToTable("BulletinBoards");
}); });
modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", b =>
{
b.Property<int>("IdBulletinBoardPage")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<int>("Duration")
.HasColumnType("int");
b.Property<int>("IdBulletinBoard")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("longtext");
b.HasKey("IdBulletinBoardPage");
b.HasIndex("IdBulletinBoard");
b.ToTable("BulletinBoardPage");
});
modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.Note", b => modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.Note", b =>
{ {
b.Property<int>("IdNote") b.Property<int>("IdNote")
@@ -152,7 +175,7 @@ namespace ZpcBulletinBoard.Migrations
b.Property<int>("Height") b.Property<int>("Height")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("IdBulletinBoard") b.Property<int>("IdBulletinBoardPage")
.HasColumnType("int"); .HasColumnType("int");
b.Property<string>("Title") b.Property<string>("Title")
@@ -170,7 +193,7 @@ namespace ZpcBulletinBoard.Migrations
b.HasKey("IdNote"); b.HasKey("IdNote");
b.HasIndex("IdBulletinBoard"); b.HasIndex("IdBulletinBoardPage");
b.ToTable("Notes"); b.ToTable("Notes");
}); });
@@ -342,10 +365,10 @@ namespace ZpcBulletinBoard.Migrations
.IsRequired(); .IsRequired();
}); });
modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.Note", b => modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", b =>
{ {
b.HasOne("ZpcBulletinBoard.Models.Editor.BulletinBoard", "BulletinBoard") b.HasOne("ZpcBulletinBoard.Models.Editor.BulletinBoard", "BulletinBoard")
.WithMany("Notes") .WithMany("Pages")
.HasForeignKey("IdBulletinBoard") .HasForeignKey("IdBulletinBoard")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@@ -353,7 +376,23 @@ namespace ZpcBulletinBoard.Migrations
b.Navigation("BulletinBoard"); b.Navigation("BulletinBoard");
}); });
modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.Note", b =>
{
b.HasOne("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", "BulletinBoardPage")
.WithMany("Notes")
.HasForeignKey("IdBulletinBoardPage")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("BulletinBoardPage");
});
modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoard", b => modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoard", b =>
{
b.Navigation("Pages");
});
modelBuilder.Entity("ZpcBulletinBoard.Models.Editor.BulletinBoardPage", b =>
{ {
b.Navigation("Notes"); b.Navigation("Notes");
}); });

View File

@@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using ZpcBulletinBoard.Classes;
namespace ZpcBulletinBoard.Models.Editor namespace ZpcBulletinBoard.Models.Editor
{ {
@@ -29,9 +30,11 @@ namespace ZpcBulletinBoard.Models.Editor
[Display(Name = "Razmerje")] [Display(Name = "Razmerje")]
public RatioEnum Ratio { get; set; } public RatioEnum Ratio { get; set; }
[NotMapped] public string RatioString => Ratio.GetAttributeOfType<DisplayAttribute>().Name ?? "";
// InvoicePart // InvoicePart
[InverseProperty("BulletinBoard")] [InverseProperty("BulletinBoard")]
public virtual ICollection<Note> Notes { get; set; } public virtual ICollection<BulletinBoardPage> Pages { get; set; }
} }
} }

View File

@@ -0,0 +1,31 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ZpcBulletinBoard.Models.Editor
{
public class BulletinBoardPage
{
[Key]
public int IdBulletinBoardPage { get; set; }
[Required]
[ForeignKey("BulletinBoard")]
public int IdBulletinBoard { get; set; }
[Required]
[Display(Name = "Ime")]
public string Name { get; set; }
[Required]
[Display(Name = "Trajanje")]
public int Duration { get; set; }
// ForeignKey
public BulletinBoard BulletinBoard { get; set; }
[InverseProperty("BulletinBoardPage")]
public virtual ICollection<Note> Notes { get; set; }
}
}

View File

@@ -9,8 +9,8 @@ namespace ZpcBulletinBoard.Models.Editor
public int IdNote { get; set; } public int IdNote { get; set; }
[Required] [Required]
[ForeignKey("BulletinBoard")] [ForeignKey("BulletinBoardPage")]
public int IdBulletinBoard { get; set; } public int IdBulletinBoardPage { get; set; }
[Required] [Required]
public int X { get; set; } public int X { get; set; }
@@ -31,6 +31,6 @@ namespace ZpcBulletinBoard.Models.Editor
public string Content { get; set; } public string Content { get; set; }
// ForeignKey // ForeignKey
public BulletinBoard BulletinBoard{ get; set; } public BulletinBoardPage BulletinBoardPage { get; set; }
} }
} }

View File

@@ -36,13 +36,13 @@ namespace ZpcBulletinBoard.Pages.Boards
{ {
Ratio = BulletinBoard.RatioEnum.Ratio16To9, Ratio = BulletinBoard.RatioEnum.Ratio16To9,
Guid = Guid.NewGuid(), Guid = Guid.NewGuid(),
Notes = new List<Note>() Pages = new List<BulletinBoardPage>()
}; };
return Page(); return Page();
} }
var tmpBoard = await context.BulletinBoards.Include(x => x.Notes) var tmpBoard = await context.BulletinBoards.Include(x => x.Pages)
.FirstOrDefaultAsync(m => m.Guid == guid); .FirstOrDefaultAsync(m => m.Guid == guid);

View File

@@ -11,7 +11,7 @@ using ZpcBulletinBoard.Models.Editor;
namespace ZpcBulletinBoard.Pages.Boards namespace ZpcBulletinBoard.Pages.Boards
{ {
//[Authorize] [Authorize]
public class IndexModel(ApplicationDbContext context) : PageModel public class IndexModel(ApplicationDbContext context) : PageModel
{ {
public IList<BulletinBoard> Boards { get;set; } public IList<BulletinBoard> Boards { get;set; }

View File

@@ -15,13 +15,8 @@
<div class="card"> <div class="card">
<div class="card-body div-main-body"> <div class="card-body div-main-body">
<div class="form-inline div-tools"> <div class="form-inline div-tools">
<select class="form-control input-xs">
<option id="1">Prvi board</option>
<option id="2">Drugi</option>
<option id="3">sad</option>
</select>
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-default btn-sm"> <button type="button" class="btn btn-default btn-sm" onclick="addNewNote()">
<i class="far fa-plus"></i> <i class="far fa-plus"></i>
</button> </button>
<button type="button" class="btn btn-default btn-sm"> <button type="button" class="btn btn-default btn-sm">
@@ -42,6 +37,35 @@
</div> </div>
</div> </div>
<div id="divModalSelectBoard" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Izberi oglasno desko</h5>
<button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<table class="table">
<thead>
<tr>
<th>Naziv</th>
</tr>
</thead>
<tbody id="tbodyModalSelectBoard">
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" onclick="saveModalEditNote();">Save changes</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="divModalEditNote" class="modal" tabindex="-1" role="dialog"> <div id="divModalEditNote" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document"> <div class="modal-dialog modal-lg" role="document">
<div class="modal-content"> <div class="modal-content">
@@ -63,6 +87,7 @@
</div> </div>
</div> </div>
@Html.AntiForgeryToken()
@section Scripts @section Scripts
{ {

View File

@@ -1,9 +1,13 @@
using System.Data.Entity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using ZpcBulletinBoard.Data;
namespace ZpcBulletinBoard.Pages.Editor namespace ZpcBulletinBoard.Pages.Editor
{ {
public class EditMainModel(ILogger<EditMainModel> logger) : PageModel [Authorize]
public class EditMainModel(ILogger<EditMainModel> logger, ApplicationDbContext context) : PageModel
{ {
private readonly ILogger<EditMainModel> _logger = logger; private readonly ILogger<EditMainModel> _logger = logger;
@@ -11,5 +15,20 @@ namespace ZpcBulletinBoard.Pages.Editor
{ {
} }
public IActionResult OnGetBoards()
{
var boards= context.BulletinBoards.ToList();
return new JsonResult(new { successful = true, error = $"", boards });
}
public IActionResult OnGetBoard(int id)
{
var board = context.BulletinBoards.Include(x => x.Pages)
.FirstOrDefault(x => x.IdBulletinBoard == id);
return new JsonResult(new { successful = true, error = $"", board });
}
} }
} }

View File

@@ -1,8 +1,10 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
namespace ZpcBulletinBoard.Pages namespace ZpcBulletinBoard.Pages
{ {
[Authorize]
public class IndexModel : PageModel public class IndexModel : PageModel
{ {
private readonly ILogger<IndexModel> _logger; private readonly ILogger<IndexModel> _logger;

View File

@@ -0,0 +1,6 @@
@page
@model ZpcBulletinBoard.Pages.SetupNew.SetupModel
@{
ViewData["Title"] = "SetupNew";
Layout = "~/Pages/Shared/_LayoutBlank.cshtml";
}

View File

@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using ZpcBulletinBoard.Data;
using ZpcBulletinBoard.Models;
namespace ZpcBulletinBoard.Pages.SetupNew
{
//[Authorize(Roles = "Administrator")]
public class SetupModel : PageModel
{
private readonly ApplicationDbContext _context;
private readonly UserManager<IdentityApplicationUser> _userManager;
private readonly SignInManager<IdentityApplicationUser> _signInManager;
private readonly RoleManager<IdentityApplicationRole> _roleManager;
private readonly ILogger<SetupModel> _logger;
public SetupModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager, SignInManager<IdentityApplicationUser> signInManager, ILogger<SetupModel> logger, RoleManager<IdentityApplicationRole> roleManager)
{
_context = context;
_userManager = userManager;
_signInManager = signInManager;
_logger = logger;
_roleManager = roleManager;
}
public async Task<IActionResult> OnGetAsync()
{
//Ze obstajajo userji
//if (_userManager.Users.Any())
// return RedirectToPage("/User/Login");
var rolesDefinitions = new List<(string RoleName, string RoleDescription)>
{
("User", "Uporabnik"),
("Administrator", "Administratorji"),
};
foreach (var roleDefinition in rolesDefinitions)
{
if (!_roleManager.RoleExistsAsync(roleDefinition.RoleName).Result)
{
var role = new IdentityApplicationRole
{
Name = roleDefinition.RoleName,
Description = roleDefinition.RoleDescription
};
_roleManager.CreateAsync(role).Wait();
}
}
var user = await _userManager.FindByNameAsync("admin");
if (user == null)
{
IdentityApplicationUser identityApplicationUser = new IdentityApplicationUser
{
Name = "Master",
Surname = "Admin",
UserName = "admin",
NormalizedUserName = "admin",
Email = "admin@domain.com",
NormalizedEmail = "admin@domain.com",
EmailConfirmed = true,
DateCreated = DateTime.Now,
DateValidUntil = DateTime.MaxValue,
PhoneNumber = "070777777",
PhoneNumberConfirmed = true,
Active = true,
};
var result = await _userManager.CreateAsync(identityApplicationUser, "*zpcBulletinBoard2024*");
if (result.Succeeded)
{
_userManager.AddToRoleAsync(identityApplicationUser, "Administrator").Wait();
//return RedirectToPage("/Administration/Users/Index");
}
else
{
//ModelState.AddModelError("", string.Join(",", identityResult.Errors.Select(x => x.Description)));
}
}
return RedirectToPage("/User/Login");
}
//public async Task<IActionResult> OnPostAsync(string returnUrl = null)
//{
// var user = await _userManager.GetUserAsync(User);
// await _signInManager.SignOutAsync();
// _logger.LogInformation($"Logout: {user.Name} {user.Surname} - {user.Company.Title}");
// if (returnUrl != null)
// {
// return LocalRedirect(returnUrl);
// }
// return RedirectToPage();
//}
}
}

View File

@@ -0,0 +1,13 @@
@{
Layout = "Shared/_Application";
}
@section Styles {
@await RenderSectionAsync("Styles", required: false)
}
@RenderBody()
@section Scripts {
@await RenderSectionAsync("Scripts", required: false)
}

View File

@@ -0,0 +1,48 @@
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
for details on configuring this project to bundle and minify static web assets. */
a.navbar-brand {
white-space: normal;
text-align: center;
word-break: break-all;
}
a {
color: #0077cc;
}
.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
.border-top {
border-top: 1px solid #e5e5e5;
}
.border-bottom {
border-bottom: 1px solid #e5e5e5;
}
.box-shadow {
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
}
button.accept-policy {
font-size: 1rem;
line-height: inherit;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
white-space: nowrap;
line-height: 60px;
}

View File

@@ -4,7 +4,7 @@
@model ZpcBulletinBoard.Pages.User.LoginModel @model ZpcBulletinBoard.Pages.User.LoginModel
@{ @{
ViewData["Title"] = "Prijava"; ViewData["Title"] = "Prijava";
Layout = "~/Pages/Shared/_Layout.cshtml"; Layout = "~/Pages/Shared/_LayoutBlank.cshtml";
} }
@section Styles { @section Styles {
@@ -24,10 +24,10 @@
<div class="ui-bg-overlay bg-dark opacity-50"></div> <div class="ui-bg-overlay bg-dark opacity-50"></div>
<div class="w-100 text-white px-5"> <div class="w-100 text-white px-5">
<h1 class="display-2 font-weight-bolder mb-4"> <h1 class="display-2 font-weight-bolder mb-4">
EveryThing ZPC
</h1> </h1>
<div class="text-large font-weight-light"> <div class="text-large font-weight-light">
Oblačna aplikacija Bulletin board
</div> </div>
</div> </div>
</div> </div>
@@ -64,10 +64,6 @@
<button type="submit" class="btn btn-primary">Prijava</button> <button type="submit" class="btn btn-primary">Prijava</button>
</div> </div>
</form> </form>
<div class="text-center text-muted">
Ste pozabili geslo? <a href="javascript:void(0)">Kliknite tukaj za ponastavitev</a>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -29,6 +29,7 @@ using Microsoft.EntityFrameworkCore;
//using Microsoft.AspNetCore.Authentication.Negotiate; //using Microsoft.AspNetCore.Authentication.Negotiate;
using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.HttpOverrides;
using ZpcBulletinBoard.Data; using ZpcBulletinBoard.Data;
using ZpcBulletinBoard.Models;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@@ -36,9 +37,61 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddRazorPages(); builder.Services.AddRazorPages();
//TODO before publish
var connectionString = builder.Configuration.GetConnectionString("DataConnection"); var connectionString = builder.Configuration.GetConnectionString("DataConnection");
//var sqlHost = Environment.GetEnvironmentVariable("MYSQL_SERVER");
//var sqlUser = Environment.GetEnvironmentVariable("MYSQL_USER");
//var sqlPassword = Environment.GetEnvironmentVariable("MYSQL_PASSWORD");
//var sqlDatabase = Environment.GetEnvironmentVariable("MYSQL_DATABASE");
//var connectionString = $"server={sqlHost};user={sqlUser};password={sqlPassword};database={sqlDatabase};SSL Mode=None";
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString))); builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)));
builder.Services.AddIdentity<IdentityApplicationUser, IdentityApplicationRole>().AddEntityFrameworkStores<ApplicationDbContext>().AddDefaultTokenProviders();
builder.Services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");
builder.Services.Configure<IdentityOptions>(options =>
{
// Password settings
options.Password.RequireDigit = true;
options.Password.RequireLowercase = true;
options.Password.RequireNonAlphanumeric = true;
options.Password.RequireUppercase = true;
options.Password.RequiredLength = 8;
options.Password.RequiredUniqueChars = 1;
// Lockout settings
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5);
options.Lockout.MaxFailedAccessAttempts = 3;
options.Lockout.AllowedForNewUsers = true;
// User settings
options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
options.User.RequireUniqueEmail = true;
});
builder.Services.ConfigureApplicationCookie(options =>
{
// Cookie
options.Cookie.MaxAge = TimeSpan.FromHours(3);
options.Cookie.HttpOnly = true;
options.SlidingExpiration = true;
options.Cookie.SecurePolicy = CookieSecurePolicy.None;//Samo unencripted na locas
options.LoginPath = $"/User/Login";
options.LogoutPath = $"/User/Logout";
options.AccessDeniedPath = $"/";
options.ExpireTimeSpan = TimeSpan.FromMinutes(15);//Povecano na 15min
});
builder.Services.Configure<IISOptions>(options =>
{
options.AutomaticAuthentication = false;
});
builder.Services.AddDataProtection().SetApplicationName("ZpcBulletinBoard").PersistKeysToFileSystem(new DirectoryInfo(@"Keys/"));
var app = builder.Build(); var app = builder.Build();
//app.UseStaticFiles(new StaticFileOptions //app.UseStaticFiles(new StaticFileOptions
@@ -55,6 +108,15 @@ if (!app.Environment.IsDevelopment())
app.UseHsts(); app.UseHsts();
} }
var defaultCulture = new CultureInfo("sl-SI");
var localizationOptions = new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture(defaultCulture),
SupportedCultures = new List<CultureInfo> { defaultCulture },
SupportedUICultures = new List<CultureInfo> { defaultCulture }
};
app.UseRequestLocalization(localizationOptions);
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseStaticFiles(); app.UseStaticFiles();

View File

@@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>02904645-4084-486e-a036-9081aa0cef47</UserSecretsId> <UserSecretsId>02904645-4084-486e-a036-9081aa0cef47</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileRunEnvironmentFiles>Dockerfile.env</DockerfileRunEnvironmentFiles>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -7,6 +7,6 @@
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"ConnectionStrings": { "ConnectionStrings": {
"DataConnection": "server=192.168.1.12;user=david;password=*staleker*;database=ZpcBulletinBoard" "DataConnection": "server=192.168.1.12;user=david;password=*staleker*;database=ZpcBulletinBoard;SSL Mode=None"
} }
} }

View File

@@ -1,31 +1,12 @@
$(function () { $(function () {
loadBoard();
loadNotes();
}); });
const ratio = '16:9'
let divCanvas; let divCanvas;
let canWidth; let canWidth;
let canHeight; let canHeight;
let notes = []; let notes = [];
function loadBoard(){
let placeholder = $('#divPlaceholder');
placeholder.empty();
let tmpSplit = ratio.split(':');
canWidth = placeholder.width();
canHeight = canWidth / (parseFloat(tmpSplit[0]) / parseFloat(tmpSplit[1]));
divCanvas = $(`<div id='divCanvas'></div>`);
placeholder.append(divCanvas);
divCanvas.css({
'width': '100%',
'height': canHeight + 'px',
'background-color': 'white',
'padding': '5px'
});
}
function loadNotes(){ function loadNotes(){
let note = new Note(1, divCanvas, 200, 0, 400, 240, '<h3>Naslov</h3><hr/><p>Test</p>' ); let note = new Note(1, divCanvas, 200, 0, 400, 240, '<h3>Naslov</h3><hr/><p>Test</p>' );
@@ -40,6 +21,18 @@ function loadNotes(){
}); });
} }
function addNewNote(){
let tmpId = -1;
notes.forEach(note => {
if (note.id <= tmpId){
tmpId = note.id -1;
}
});
let note = new Note(tmpId, divCanvas, 0, 0, 400, 240, 'Vnesi besedilo');
notes.push(note);
note.refresh();
}
function openModalEditNote(id){ function openModalEditNote(id){
$('#inpModalEditNoteIdNote').val(id); $('#inpModalEditNoteIdNote').val(id);
note = getNote(id); note = getNote(id);
@@ -47,7 +40,7 @@ function openModalEditNote(id){
$('#divModalEditNote').modal('show'); $('#divModalEditNote').modal('show');
$('#divModalEditNoteSummernote').summernote('destroy'); $('#divModalEditNoteSummernote').summernote('destroy');
$('#divModalEditNoteSummernote').html(note.content); $('#divModalEditNoteSummernote').html(note.content);
$('#divModalEditNoteSummernote').summernote({}); $('#divModalEditNoteSummernote').summernote({height: 400,});
} }
function saveModalEditNote(){ function saveModalEditNote(){
@@ -89,3 +82,78 @@ function svgTest(){
}); });
} }
function openModalSelectBoard() {
$.blockUI();
$.ajax({
type: "GET",
url: "/Editor/EditMain/?handler=Boards",
data: {
},
success: function (data) {
if (data.successful){
let tmp = '';
data.boards.forEach(element => {
tmp += `<tr data-id='${element.idBulletinBoard}' onclick='modalSelectBoardSelect(this);'>`;
tmp += '<td>' + element.name + '</td>';
tmp += '</tr>';
});
$('#tbodyModalSelectBoard').html(tmp);
$('#divModalSelectBoard').modal('show');
} else {
console.log(data);
alert(data);
}
$.unblockUI();
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr);
alert(xhr.responseText);
$.unblockUI();
}
});
}
function modalSelectBoardSelect(element){
loadBoard(parseInt($(element).attr('data-id')));
$('#divModalSelectBoard').modal('hide');
}
function loadBoard(id){
$.blockUI();
$.ajax({
type: "GET",
url: "/Editor/EditMain/?handler=Board",
data: {
id
},
success: function (data) {
if (data.successful){
let placeholder = $('#divPlaceholder');
placeholder.empty();
console.log(data);
let tmpSplit = data.board.ratioString.split(':');
canWidth = placeholder.width();
canHeight = canWidth / (parseFloat(tmpSplit[0]) / parseFloat(tmpSplit[1]));
divCanvas = $(`<div id='divCanvas'></div>`);
placeholder.append(divCanvas);
divCanvas.css({
'width': '100%',
'height': canHeight + 'px',
'background-color': 'white',
'padding': '5px'
});
loadNotes();
} else {
console.log(data);
alert(data);
}
$.unblockUI();
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr);
alert(xhr.responseText);
$.unblockUI();
}
});
}