diff --git a/EveryThing/Classess/Global.cs b/EveryThing/Classess/Global.cs new file mode 100644 index 0000000..00d9de3 --- /dev/null +++ b/EveryThing/Classess/Global.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace EveryThing.Classess +{ + public static class Global + { + public static T GetAttributeOfType(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(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()) + { + object tempObject = GetAttributeOfType(tempEnumValue); + + titleValue.Add((Convert.ToInt32(tempEnumValue), (T)tempObject)); + } + + return titleValue.ToList(); + } + } +} diff --git a/EveryThing/Data/ApplicationDbContext.cs b/EveryThing/Data/ApplicationDbContext.cs index 073a8ae..40d9d9e 100644 --- a/EveryThing/Data/ApplicationDbContext.cs +++ b/EveryThing/Data/ApplicationDbContext.cs @@ -48,6 +48,8 @@ namespace EveryThing.Data public DbSet CodeTableItems { get; set; } public DbSet Invoices { get; set; } public DbSet InvoiceItems { get; set; } + public DbSet CodeTablePrePostText { get; set; } + public DbSet CodeTablePrePostTextLink { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { diff --git a/EveryThing/Models/CodeTable/CodeTablePrePostText.cs b/EveryThing/Models/CodeTable/CodeTablePrePostText.cs index 1c971c6..2b90c31 100644 --- a/EveryThing/Models/CodeTable/CodeTablePrePostText.cs +++ b/EveryThing/Models/CodeTable/CodeTablePrePostText.cs @@ -21,6 +21,11 @@ namespace EveryThing.Models.CodeTable [Display(Name = "Vsebina")] public string Content { get; set; } + [NotMapped] + public string ContentDisplay => Content == null ? "" : Content.Length >= 30 + ? Content.Substring(0, 30) + : Content; + // ForeingKey public CodeTableCompany Company { get; set; } diff --git a/EveryThing/Pages/CodeTablePrePostText/AddEdit.cshtml b/EveryThing/Pages/CodeTablePrePostText/AddEdit.cshtml new file mode 100644 index 0000000..5a5aa12 --- /dev/null +++ b/EveryThing/Pages/CodeTablePrePostText/AddEdit.cshtml @@ -0,0 +1,187 @@ +@page "{handler?}" +@model EveryThing.Pages.CodeTablePrePostText.AddEditModel + +@{ + ViewData["Title"] = "Urejanje klavzule"; + Layout = "~/Pages/Layouts/_Layout.cshtml"; +} + + + + + + +

+ + Nalog / + @if (Model.PrePostText.IdPrePostText > 0) + { + Urejanje + } + else + { + Vnos + } + +

+ + + +
+@Html.AntiForgeryToken() + +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} + + + + + + +} \ No newline at end of file diff --git a/EveryThing/Pages/CodeTablePrePostText/AddEdit.cshtml.cs b/EveryThing/Pages/CodeTablePrePostText/AddEdit.cshtml.cs new file mode 100644 index 0000000..0bc7f7f --- /dev/null +++ b/EveryThing/Pages/CodeTablePrePostText/AddEdit.cshtml.cs @@ -0,0 +1,169 @@ +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 EveryThing.Data; +using EveryThing.Models; +using DocumentFormat.OpenXml.Spreadsheet; +using EveryThing.Models.CodeTable; +using EveryThing.Classess; + +namespace EveryThing.Pages.CodeTablePrePostText + +{ + [Authorize(Roles = "Administrator,TransportThingUser,InvoicingUser")] + public class AddEditModel : PageModel + { + private readonly ApplicationDbContext _context; + private readonly UserManager _userManager; + + public AddEditModel(ApplicationDbContext context, UserManager userManager) + { + _context = context; + _userManager = userManager; + } + + [BindProperty] + public Models.CodeTable.CodeTablePrePostText PrePostText { get; set; } + + + public async Task OnGetAsync(int? id) + { + var user = _userManager.GetUserAsync(User).Result; + + + if (id == null) + { + PrePostText = new Models.CodeTable.CodeTablePrePostText + { + Content = "", + IdCompanyFk = user.IdCompanyFk + }; + + return Page(); + } + + PrePostText = await _context.CodeTablePrePostText + .FirstOrDefaultAsync(m => m.IdPrePostText == id && m.IdCompanyFk == user.IdCompanyFk); + + + if (PrePostText == null) + { + return NotFound(); + } + + + return Page(); + } + + public async Task OnPostOrderAsync() + { + System.Diagnostics.Debug.WriteLine("OnPostOrderAsync"); + + var user = _userManager.GetUserAsync(User).Result; + + if (!ModelState.IsValid) + { + ViewData["IdPartnerFk"] = new SelectList(_context.CodeTablePartners.Where(x => x.IdCompanyFk == user.IdCompanyFk), "IdPartner", "Title"); + ViewData["IdVehicleFk"] = new SelectList(_context.Vehicles.Where(x => x.IdCompanyFk == user.IdCompanyFk), "IdVehicle", "RegistrationNumber"); + return Page(); + } + + PrePostText.Content = PrePostText.Content.Replace("

", ""); + + if (PrePostText.IdPrePostText > 0) + { + _context.Attach(PrePostText).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!PrePostTextExists(PrePostText.IdPrePostText)) + { + return NotFound(); + } + else + { + throw; + } + } + + return Page(); + } + + // OrderNumber and OrderYear + + _context.CodeTablePrePostText.Add(PrePostText); + await _context.SaveChangesAsync(); + + + return new JsonResult(new { id = PrePostText.IdPrePostText}); + } + + + private bool PrePostTextExists(int id) + { + return _context.CodeTablePrePostText.Any(e => e.IdPrePostText == id); + } + + public IActionResult OnGetLinksTable(int idPrePostText) + { + var insertedLinks = _context.CodeTablePrePostTextLink + .Where(x => x.IdPrePostTextFk == idPrePostText); + + var tableLinks = new StringBuilder(); + + typeof(CodeTablePrePostTextLink.LinkEnum).GetEnumListClass().ForEach(link => + { + var insertedLink = insertedLinks.FirstOrDefault(x => (int)x.Link == link.EnumValue); + tableLinks.Append($""); + tableLinks.Append($" 0 ? "checked='checked'" : "")}/>"); + tableLinks.Append($"{link.EnumAttribute.Name}"); + tableLinks.Append(""); + }); + + return new JsonResult(new { tableLinks = tableLinks.ToString(), successful = true }); + } + + public IActionResult OnPostLinkToggle(int idPrePostText, int link, int idPrePostTextLink) + { + var user = _userManager.GetUserAsync(User).Result; + var idLink = 0; + + var exitingLink = + _context.CodeTablePrePostTextLink.FirstOrDefault(x => x.IdPrePostTextLink == idPrePostTextLink && x.IdPrePostTextFk == idPrePostText); + + if (exitingLink != null) + { + _context.CodeTablePrePostTextLink.Remove(exitingLink); + _context.SaveChanges(); + } + else + { + var newLink = new CodeTablePrePostTextLink + { + IdPrePostTextFk = idPrePostText, + Link = (CodeTablePrePostTextLink.LinkEnum)link + }; + + _context.CodeTablePrePostTextLink.Add(newLink); + _context.SaveChanges(); + idLink = newLink.IdPrePostTextLink; + } + + return new JsonResult(new { error = "", successful = true, idLink }); + } + } +} diff --git a/EveryThing/Pages/CodeTablePrePostText/Index.cshtml b/EveryThing/Pages/CodeTablePrePostText/Index.cshtml new file mode 100644 index 0000000..64c923a --- /dev/null +++ b/EveryThing/Pages/CodeTablePrePostText/Index.cshtml @@ -0,0 +1,67 @@ +@page +@model EveryThing.Pages.CodeTablePrePostText.IndexModel + +@{ + ViewData["Title"] = "Klavzule"; + Layout = "~/Pages/Layouts/_Layout.cshtml"; +} + +

+ + Klavzule / Pregled + +

+ +
+
+
+
+ + +
+
+
+
+ +
+ +
+ Seznam klavzul +
+ + + + + + + + + + @foreach (var item in Model.PrePostTexts) + { + + + + + } + +
+ Klavzula +
+ @Html.DisplayFor(modelItem => item.ContentDisplay) + + +
+ + +
+ +@section Scripts { + +} \ No newline at end of file diff --git a/EveryThing/Pages/CodeTablePrePostText/Index.cshtml.cs b/EveryThing/Pages/CodeTablePrePostText/Index.cshtml.cs new file mode 100644 index 0000000..a3f0534 --- /dev/null +++ b/EveryThing/Pages/CodeTablePrePostText/Index.cshtml.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using EveryThing.Data; +using EveryThing.Models; +using EveryThing.Models.Transport; +using Microsoft.AspNetCore.Authorization; + +namespace EveryThing.Pages.CodeTablePrePostText +{ + [Authorize(Roles = "Administrator,TransportThingUser,InvoicingUser")] + public class IndexModel : PageModel + { + private readonly EveryThing.Data.ApplicationDbContext _context; + private readonly UserManager _userManager; + + public IndexModel(EveryThing.Data.ApplicationDbContext context, UserManager userManager) + { + _context = context; + _userManager = userManager; + } + + public IList PrePostTexts { get;set; } + + public async Task OnGetAsync(string searchString) + { + ViewData["SearchString"] = searchString; + + var user = _userManager.GetUserAsync(User).Result; + + PrePostTexts = await _context.CodeTablePrePostText + .Where(x => x.IdCompanyFk == user.IdCompanyFk) + .OrderByDescending(x => x.Content) + .ToListAsync(); + + if (!string.IsNullOrEmpty(searchString)) + { + PrePostTexts = PrePostTexts.Where(x => x.Content == searchString).ToList(); + } + } + + + } +} diff --git a/EveryThing/Pages/Layouts/Partials/_LayoutSidenav.cshtml b/EveryThing/Pages/Layouts/Partials/_LayoutSidenav.cshtml index be1284e..277aae1 100644 --- a/EveryThing/Pages/Layouts/Partials/_LayoutSidenav.cshtml +++ b/EveryThing/Pages/Layouts/Partials/_LayoutSidenav.cshtml @@ -125,6 +125,13 @@
Vrste goriva
} + + @if (User.IsInRole("Administrator") || User.IsInRole("TransportThingUser") || User.IsInRole("InvoicingUser")) + { +
  • +
    Klavzule
    +
  • + } } @*
  • Ostali šifranti