From 13e43623437117c2ce97ff613a7f0f6ff539ced0 Mon Sep 17 00:00:00 2001 From: Maier Stephan SI Date: Fri, 22 Sep 2023 06:59:15 +0200 Subject: [PATCH] Sicherung vor Bootstrap Aktualsisierung --- .../Controllers/OrganizationController.cs | 54 ++++++++--- .../Controllers/ProjectController.cs | 69 ++++++++++++++ .../FSI.Prj.Mgt/Data/ApplicationDbContext.cs | 12 +-- ...052441_addedOrganizationDbSet.Designer.cs} | 19 ++-- ... 20230920052441_addedOrganizationDbSet.cs} | 13 +-- .../ApplicationDbContextModelSnapshot.cs | 15 +-- FSI.Prj.Mgt/FSI.Prj.Mgt/FSI.Prj.Mgt.csproj | 3 +- .../FSI.Prj.Mgt/Models/Organization.cs | 4 +- .../FSI.Prj.Mgt/Models/TreeViewNode.cs | 9 ++ .../FSI.Prj.Mgt/Views/Home/Privacy.cshtml | 30 ++++++ .../Views/Organization/Index.cshtml | 69 +++++++++++--- .../Views/Project/CreateEdit.cshtml | 6 ++ .../FSI.Prj.Mgt/Views/Project/Index.cshtml | 52 ++++++++-- .../Views/Project/_CreateEditPartial.cshtml | 95 +++++++++++++++++++ .../FSI.Prj.Mgt/Views/Shared/_Layout.cshtml | 3 + FSI.Prj.Mgt/FSI.Prj.Mgt/wwwroot/js/site.js | 26 +++++ 16 files changed, 410 insertions(+), 69 deletions(-) rename FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/{20230919114347_addedOrganizationSet.Designer.cs => 20230920052441_addedOrganizationDbSet.Designer.cs} (97%) rename FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/{20230919114347_addedOrganizationSet.cs => 20230920052441_addedOrganizationDbSet.cs} (78%) create mode 100644 FSI.Prj.Mgt/FSI.Prj.Mgt/Models/TreeViewNode.cs create mode 100644 FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/_CreateEditPartial.cshtml diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/OrganizationController.cs b/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/OrganizationController.cs index 6027939..ba4b20d 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/OrganizationController.cs +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/OrganizationController.cs @@ -2,6 +2,8 @@ using FSI.Prj.Mgt.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Storage; +using Newtonsoft.Json; using X.PagedList; namespace FSI.Prj.Mgt.Controllers @@ -18,26 +20,48 @@ namespace FSI.Prj.Mgt.Controllers public IActionResult Index() { - var organizations = _context.Organizations.ToList(); + List nodes = new(); - var org = organizations.Where(x => x.ParentId == 0 || x.ParentId == null).FirstOrDefault(); - - SetChildren(org, organizations); - - return View(org); - } - - private void SetChildren(Organization model, List organizations) - { - var childs = organizations.Where(x => x.ParentId == model.Id).ToList(); - - foreach (var item in childs) + // Loop and add the Parent Nodes + foreach (Organization organization in _context.Organizations) { - SetChildren(item, organizations); - model.Childs.Add(item); + if (organization.ParentId == null) + { + nodes.Add(new TreeViewNode + { + id = organization.Id.ToString(), + parent = "#", + text = organization.Name, + }); + } + else + { + nodes.Add(new TreeViewNode + { + id = organization.Id.ToString(), + parent = organization.ParentId.ToString(), + text = organization.Name, + }); + } } + ViewBag.Json = JsonConvert.SerializeObject(nodes); + + return View(); } + [HttpPost] + public IActionResult Index (string selectedItems) + { + if (selectedItems != null) + { + List items = JsonConvert.DeserializeObject>(selectedItems); + } + + return RedirectToAction("Index", "Organization"); + } + + + } } \ No newline at end of file diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/ProjectController.cs b/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/ProjectController.cs index 6e3590d..a3f555d 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/ProjectController.cs +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Controllers/ProjectController.cs @@ -117,5 +117,74 @@ namespace FSI.Prj.Mgt.Controllers return RedirectToAction("Index"); } + + + + [HttpGet] + public IActionResult Create() + { + //ViewBag.Plants = _context.Plants; + + //if (id == 0) + //{ + Project prj = new Project(); + + return PartialView("_CreateEditPartial", prj); + //} + + //var project = _context.Projects.Find(id); + + //if (project == null) + //{ + // return NotFound(); + //} + + //return PartialView("_CreateEditPartial", project); + } + + [HttpPost] + public IActionResult Create(Project project) + { + if (project.Id == 0) + { + var highestPrjNo = 0; + int prjYear = 0; + int prjNo = 0; + + if (_context.Projects.Count() > 0) + { + highestPrjNo = _context.Projects.Max(x => x.No); + prjYear = highestPrjNo; + + // Projekt Jahr freistellen + while (prjYear >= 100) + prjYear /= 10; + + // Laufende Nr. des Jahres freistellen + prjNo = highestPrjNo >= 1000 ? highestPrjNo % 1000 : highestPrjNo; + } + + // Neue Projekt Nummer berechnen + if (prjYear == int.Parse(DateTime.Now.ToString("yy"))) + { + project.No = prjYear * 1000 + prjNo + 1; + } + else + { + project.No = int.Parse(DateTime.Now.ToString("yy")) * 1000 + 1; + } + + _context.Projects.Add(project); + } + else + { + _context.Projects.Update(project); + + } + + _context.SaveChanges(); + + return PartialView("_CreateEditPartial", project); + } } } diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/ApplicationDbContext.cs b/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/ApplicationDbContext.cs index e4a4730..0af7744 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/ApplicationDbContext.cs +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/ApplicationDbContext.cs @@ -7,16 +7,16 @@ namespace FSI.Prj.Mgt.Data public class ApplicationDbContext : IdentityDbContext { - public DbSet Projects { get; set; } - - public DbSet Plants { get; set; } - - public DbSet Organizations { get; set; } - public ApplicationDbContext(DbContextOptions options) : base(options) { } + + public DbSet Projects { get; set; } + + public DbSet Plants { get; set; } + + public DbSet Organizations { get; set; } } } \ No newline at end of file diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230919114347_addedOrganizationSet.Designer.cs b/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230920052441_addedOrganizationDbSet.Designer.cs similarity index 97% rename from FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230919114347_addedOrganizationSet.Designer.cs rename to FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230920052441_addedOrganizationDbSet.Designer.cs index 532011b..0e1c949 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230919114347_addedOrganizationSet.Designer.cs +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230920052441_addedOrganizationDbSet.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace FSI.Prj.Mgt.Data.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20230919114347_addedOrganizationSet")] - partial class addedOrganizationSet + [Migration("20230920052441_addedOrganizationDbSet")] + partial class addedOrganizationDbSet { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -41,6 +41,9 @@ namespace FSI.Prj.Mgt.Data.Migrations .IsRequired() .HasColumnType("nvarchar(max)"); + b.Property("OrganizationId") + .HasColumnType("int"); + b.Property("ParentId") .HasColumnType("int"); @@ -50,7 +53,7 @@ namespace FSI.Prj.Mgt.Data.Migrations b.HasKey("Id"); - b.HasIndex("ParentId"); + b.HasIndex("OrganizationId"); b.ToTable("Organizations"); }); @@ -320,11 +323,9 @@ namespace FSI.Prj.Mgt.Data.Migrations modelBuilder.Entity("FSI.Prj.Mgt.Models.Organization", b => { - b.HasOne("FSI.Prj.Mgt.Models.Organization", "Parent") - .WithMany("Childs") - .HasForeignKey("ParentId"); - - b.Navigation("Parent"); + b.HasOne("FSI.Prj.Mgt.Models.Organization", null) + .WithMany("Organizations") + .HasForeignKey("OrganizationId"); }); modelBuilder.Entity("FSI.Prj.Mgt.Models.Project", b => @@ -391,7 +392,7 @@ namespace FSI.Prj.Mgt.Data.Migrations modelBuilder.Entity("FSI.Prj.Mgt.Models.Organization", b => { - b.Navigation("Childs"); + b.Navigation("Organizations"); }); #pragma warning restore 612, 618 } diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230919114347_addedOrganizationSet.cs b/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230920052441_addedOrganizationDbSet.cs similarity index 78% rename from FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230919114347_addedOrganizationSet.cs rename to FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230920052441_addedOrganizationDbSet.cs index dec7d51..d72caf1 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230919114347_addedOrganizationSet.cs +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/20230920052441_addedOrganizationDbSet.cs @@ -5,7 +5,7 @@ namespace FSI.Prj.Mgt.Data.Migrations { /// - public partial class addedOrganizationSet : Migration + public partial class addedOrganizationDbSet : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -19,22 +19,23 @@ namespace FSI.Prj.Mgt.Data.Migrations Name = table.Column(type: "nvarchar(max)", nullable: false), ShortName = table.Column(type: "nvarchar(max)", nullable: false), Description = table.Column(type: "nvarchar(max)", nullable: false), - ParentId = table.Column(type: "int", nullable: true) + ParentId = table.Column(type: "int", nullable: true), + OrganizationId = table.Column(type: "int", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Organizations", x => x.Id); table.ForeignKey( - name: "FK_Organizations_Organizations_ParentId", - column: x => x.ParentId, + name: "FK_Organizations_Organizations_OrganizationId", + column: x => x.OrganizationId, principalTable: "Organizations", principalColumn: "Id"); }); migrationBuilder.CreateIndex( - name: "IX_Organizations_ParentId", + name: "IX_Organizations_OrganizationId", table: "Organizations", - column: "ParentId"); + column: "OrganizationId"); } /// diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/ApplicationDbContextModelSnapshot.cs b/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/ApplicationDbContextModelSnapshot.cs index a0f9f28..35ad73d 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -38,6 +38,9 @@ namespace FSI.Prj.Mgt.Data.Migrations .IsRequired() .HasColumnType("nvarchar(max)"); + b.Property("OrganizationId") + .HasColumnType("int"); + b.Property("ParentId") .HasColumnType("int"); @@ -47,7 +50,7 @@ namespace FSI.Prj.Mgt.Data.Migrations b.HasKey("Id"); - b.HasIndex("ParentId"); + b.HasIndex("OrganizationId"); b.ToTable("Organizations"); }); @@ -317,11 +320,9 @@ namespace FSI.Prj.Mgt.Data.Migrations modelBuilder.Entity("FSI.Prj.Mgt.Models.Organization", b => { - b.HasOne("FSI.Prj.Mgt.Models.Organization", "Parent") - .WithMany("Childs") - .HasForeignKey("ParentId"); - - b.Navigation("Parent"); + b.HasOne("FSI.Prj.Mgt.Models.Organization", null) + .WithMany("Organizations") + .HasForeignKey("OrganizationId"); }); modelBuilder.Entity("FSI.Prj.Mgt.Models.Project", b => @@ -388,7 +389,7 @@ namespace FSI.Prj.Mgt.Data.Migrations modelBuilder.Entity("FSI.Prj.Mgt.Models.Organization", b => { - b.Navigation("Childs"); + b.Navigation("Organizations"); }); #pragma warning restore 612, 618 } diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/FSI.Prj.Mgt.csproj b/FSI.Prj.Mgt/FSI.Prj.Mgt/FSI.Prj.Mgt.csproj index 5e9f409..44ccacd 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/FSI.Prj.Mgt.csproj +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/FSI.Prj.Mgt.csproj @@ -1,4 +1,4 @@ - + net7.0 @@ -14,6 +14,7 @@ + diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Models/Organization.cs b/FSI.Prj.Mgt/FSI.Prj.Mgt/Models/Organization.cs index 629bd84..eadede4 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Models/Organization.cs +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Models/Organization.cs @@ -13,8 +13,6 @@ namespace FSI.Prj.Mgt.Models public string Description { get; set; } public int? ParentId { get; set; } - [ForeignKey("ParentId")] - public virtual Organization Parent { get; set; } - public virtual ICollection Childs { get; set; } + public virtual List Organizations{ get; set; } } } diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Models/TreeViewNode.cs b/FSI.Prj.Mgt/FSI.Prj.Mgt/Models/TreeViewNode.cs new file mode 100644 index 0000000..ec62369 --- /dev/null +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Models/TreeViewNode.cs @@ -0,0 +1,9 @@ +namespace FSI.Prj.Mgt.Models +{ + public class TreeViewNode + { + public string id { get; set; } + public string parent{ get; set; } + public string text { get; set; } + } +} diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Home/Privacy.cshtml b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Home/Privacy.cshtml index af4fb19..f23175f 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Home/Privacy.cshtml +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Home/Privacy.cshtml @@ -3,4 +3,34 @@ }

@ViewData["Title"]

+ + + +

Use this page to detail your site's privacy policy.

+ + + + + + \ No newline at end of file diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/Index.cshtml b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/Index.cshtml index 14741e3..684c68a 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/Index.cshtml +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Organization/Index.cshtml @@ -1,17 +1,60 @@ -@model FSI.Prj.Mgt.Models.Organization + +@using (Html.BeginForm("Index", "Organization", FormMethod.Post)) +{ + + + +} -
-
    -
  • - @Model.Name - @Html.Partial("Childrens", Model) -
  • -
+
- \ No newline at end of file +@section scripts{ + + + + +} diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/CreateEdit.cshtml b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/CreateEdit.cshtml index 6a99d1c..d060c98 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/CreateEdit.cshtml +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/CreateEdit.cshtml @@ -51,6 +51,12 @@
+
+
+ +
+
+ diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/Index.cshtml b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/Index.cshtml index 46bb483..f867357 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/Index.cshtml +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/Index.cshtml @@ -11,15 +11,13 @@

Projekt-Übersicht

-
- +@* +
- -
- + *@

- Suchen nach: + Suchen nach:

@@ -51,7 +49,7 @@ @project.No - @project.Plant.Name @project.Plant.SubPlantShortName + @project.Plant.Name @project.Plant.SubPlantShortName @project.Name @@ -60,7 +58,7 @@ @project.Description - @Html.DisplayFor(x => @project.Status) + @Html.DisplayFor(x => @project.Status)
@@ -75,6 +73,7 @@ + +
+ + + + + + + + + + + + + + diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/_CreateEditPartial.cshtml b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/_CreateEditPartial.cshtml new file mode 100644 index 0000000..1e2a412 --- /dev/null +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Project/_CreateEditPartial.cshtml @@ -0,0 +1,95 @@ +@model FSI.Prj.Mgt.Models.Project + + + +@* + + + *@ + + + +@* *@ + +@* + *@ \ No newline at end of file diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Shared/_Layout.cshtml b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Shared/_Layout.cshtml index 4abd4fe..bdc7bdf 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Shared/_Layout.cshtml +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/Views/Shared/_Layout.cshtml @@ -27,6 +27,9 @@ +
diff --git a/FSI.Prj.Mgt/FSI.Prj.Mgt/wwwroot/js/site.js b/FSI.Prj.Mgt/FSI.Prj.Mgt/wwwroot/js/site.js index ac49c18..bc2a9fe 100644 --- a/FSI.Prj.Mgt/FSI.Prj.Mgt/wwwroot/js/site.js +++ b/FSI.Prj.Mgt/FSI.Prj.Mgt/wwwroot/js/site.js @@ -2,3 +2,29 @@ // for details on configuring this project to bundle and minify static web assets. // Write your JavaScript code. + + +$(function () { + + var PlaceHolderElement = $('#PlaceHolderHere'); + + $('button[data-toggle="ajax-modal"]').click(function (event) { + + var url = $(this).data('url'); + var decodeUrl = decodeURIComponent(url); + $.get(decodeUrl).done(function (data) { + PlaceHolderElement.html(data); + PlaceHolderElement.find('.modal').modal('show'); + }) + }) + + PlaceHolderElement.on('click', '[data-save="modal"]', function (event) { + var form = $(this).parents('.modal').find('form'); + var actionUrl = form.attr('action'); + var url = "/project/" + actionUrl; + var sendData = from.serialize(); + $.post(url, sendData).done(function (data) { + PlaceHolderElement.find('.modal').modal('hide'); + }) + }) +}) \ No newline at end of file