Sicherung
This commit is contained in:
@@ -21,7 +21,8 @@ namespace FSI.Prj.Mgt.Controllers
|
||||
|
||||
public async Task<IActionResult> Index(string searchString, int? page)
|
||||
{
|
||||
IQueryable<Organization> items = _context.Organizations.Include(x => x.Parent);
|
||||
await UpdateFullShortName(_context.Organizations.ToList());
|
||||
IQueryable<Organization> items = _context.Organizations.Include(x => x.Parent).OrderBy(x => x.FullShortName);
|
||||
|
||||
if (!string.IsNullOrEmpty(searchString))
|
||||
{
|
||||
@@ -80,7 +81,7 @@ namespace FSI.Prj.Mgt.Controllers
|
||||
{
|
||||
var item = await _context.Organizations.FindAsync(id);
|
||||
|
||||
if (item == null)
|
||||
if (item == null) // kein Fund
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
@@ -106,6 +107,13 @@ namespace FSI.Prj.Mgt.Controllers
|
||||
ModelState.Remove("Parents");
|
||||
ModelState.Remove("FullShortName");
|
||||
|
||||
if (string.IsNullOrEmpty(item.FullShortName))
|
||||
{
|
||||
item.FullShortName = GetFullShortName(_context.Organizations.ToList(), item.ParentId, item.ShortName);
|
||||
}
|
||||
|
||||
item.ModificationTimeStamp = DateTime.Now; // Zeitstempel für Modifikation
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
|
||||
@@ -115,18 +123,22 @@ namespace FSI.Prj.Mgt.Controllers
|
||||
}
|
||||
|
||||
if (id == 0) // Insert
|
||||
{
|
||||
_context.Add(item);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
{
|
||||
try
|
||||
{
|
||||
item.CreationTimeStamp = item.ModificationTimeStamp; // Zeitstempel für Erstellung
|
||||
_context.Add(item);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else // Update
|
||||
{
|
||||
try
|
||||
{
|
||||
_context.Update(item);
|
||||
|
||||
{
|
||||
_context.Update(item);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
@@ -142,6 +154,7 @@ namespace FSI.Prj.Mgt.Controllers
|
||||
{
|
||||
var errors = ModelState.SelectMany(x => x.Value.Errors.Select(z => z.Exception));
|
||||
}
|
||||
|
||||
item.Parents.Add(new Organization());
|
||||
return Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEdit", item) });
|
||||
}
|
||||
@@ -174,17 +187,17 @@ namespace FSI.Prj.Mgt.Controllers
|
||||
// return RedirectToAction("Index", "Organization");
|
||||
//}
|
||||
|
||||
public async void UpdateFullShortName()
|
||||
public async Task UpdateFullShortName(List<Organization> organizations)
|
||||
{
|
||||
foreach (var organization in _context.Organizations)
|
||||
foreach (var organization in organizations)
|
||||
{
|
||||
foreach (var item in _context.Organizations)
|
||||
foreach (var item in organizations)
|
||||
{
|
||||
item.FullShortName = GetFullShortName(_context.Organizations.ToList(), item.ParentId, item.ShortName);
|
||||
item.FullShortName = GetFullShortName(organizations, item.ParentId, item.ShortName);
|
||||
_context.Update(item);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private string GetFullShortName(List<Organization> items, int? parentId, string? name)
|
||||
@@ -204,9 +217,7 @@ namespace FSI.Prj.Mgt.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace FSI.Prj.Mgt.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20230929113426_Init")]
|
||||
[Migration("20231003081806_Init")]
|
||||
partial class Init
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -33,6 +33,9 @@ namespace FSI.Prj.Mgt.Data.Migrations
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTimeStamp")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
@@ -40,6 +43,9 @@ namespace FSI.Prj.Mgt.Data.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("ModificationTimeStamp")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
@@ -21,6 +22,8 @@ namespace FSI.Prj.Mgt.Data.Migrations
|
||||
Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
ParentId = table.Column<int>(type: "int", nullable: true),
|
||||
Type = table.Column<int>(type: "int", nullable: false),
|
||||
CreationTimeStamp = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ModificationTimeStamp = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
FullShortName = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
@@ -30,6 +30,9 @@ namespace FSI.Prj.Mgt.Data.Migrations
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("CreationTimeStamp")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
@@ -37,6 +40,9 @@ namespace FSI.Prj.Mgt.Data.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("ModificationTimeStamp")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
@@ -38,8 +38,15 @@ namespace FSI.Prj.Mgt.Models
|
||||
[Required(ErrorMessage = "Dieses Feld wird benötigt.")]
|
||||
public OrganizationType Type { get; set; }
|
||||
|
||||
[DisplayName("vollständiger Kurzname")]
|
||||
public virtual string FullShortName { get; set; }
|
||||
[DisplayName("Erstellungsdatum")]
|
||||
public DateTime CreationTimeStamp { get; set; }
|
||||
|
||||
[DisplayName("Änderungsdatum")]
|
||||
public DateTime ModificationTimeStamp { get; set; }
|
||||
|
||||
[DisplayName("vollständiger Kurzname")]
|
||||
public string FullShortName { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public enum OrganizationType
|
||||
|
||||
@@ -10,8 +10,10 @@
|
||||
<form asp-action="AddOrEdit" asp-route-id="@Model.Id" onsubmit="return jQueryAjaxPost(this);">
|
||||
|
||||
<input hidden asp-for="Id" class="form-control" />
|
||||
<input hidden asp-for="FullShortName" class="form-control" />
|
||||
|
||||
<input hidden asp-for="FullShortName" class="form-control" />
|
||||
<input hidden asp-for="CreationTimeStamp" class="form-control" />
|
||||
<input hidden asp-for="ModificationTimeStamp" class="form-control" />
|
||||
|
||||
<div class="form-group">
|
||||
<label asp-for="ShortName" class="control-label"></label>
|
||||
<input asp-for="ShortName" class="form-control" />
|
||||
@@ -37,8 +39,8 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label asp-for="ParentId" class="control-label"></label>
|
||||
<select asp-for="ParentId" asp-items="@(new SelectList(Model.Parents, "Id", "Name"))" class="form-control" ></select>
|
||||
<label asp-for="ParentId" class="control-label"></label>
|
||||
<select asp-for="ParentId" asp-items="@(new SelectList(from x in Model.Parents select new { Value= x.Id, Text = x.FullShortName + " - " + x.Name}, "Value", "Text"))" class="form-control"></select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
@Html.DisplayNameFor(x => x.GetEnumerator().Current.Name)
|
||||
@Html.DisplayNameFor(x => x.GetEnumerator().Current.ShortName)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(x => x.GetEnumerator().Current.ShortName)
|
||||
@Html.DisplayNameFor(x => x.GetEnumerator().Current.Name)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(x => x.GetEnumerator().Current.Description)
|
||||
@@ -30,7 +30,7 @@
|
||||
<th>
|
||||
<a onclick="showInPopup('@Url.Action("AddOrEdit", "Organization", new {id = 0}, Context.Request.Scheme)','neue Organisation')" class="btn btn-success text-white">
|
||||
<i class="bi bi-plus-square"></i>
|
||||
neue
|
||||
neu
|
||||
</a>
|
||||
</th>
|
||||
</tr>
|
||||
@@ -44,12 +44,12 @@
|
||||
<td hidden>
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Name)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.ShortName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Name)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => @item.Description)
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user