diff --git a/FaKrosnoApi/Controllers/ProductController.cs b/FaKrosnoApi/Controllers/ProductController.cs new file mode 100644 index 0000000..f76c7b8 --- /dev/null +++ b/FaKrosnoApi/Controllers/ProductController.cs @@ -0,0 +1,31 @@ +using FaKrosnoEfDataModel.Dtos; +using FaKrosnoEfDataModel.Services; +using Microsoft.AspNetCore.Mvc; + +namespace FaKrosnoApi.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class ProductController(IProductService service) : Controller +{ + [HttpGet] + public async Task>> GetAll() + { + IEnumerable products = await service.GetEntities(); + return Ok(products); + } + + [HttpGet("by-index")] + public async Task>> GetByIndex([FromQuery] string indexName) + { + IEnumerable products = await service.GetEntitiesToFix(indexName); + return Ok(products); + } + + [HttpPut] + public async Task Update([FromBody] ProductDto product) + { + await service.UpdateEntity(product); + return Ok(); + } +} \ No newline at end of file diff --git a/FaKrosnoApi/Program.cs b/FaKrosnoApi/Program.cs index 81b4787..6828f42 100644 --- a/FaKrosnoApi/Program.cs +++ b/FaKrosnoApi/Program.cs @@ -98,6 +98,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddHostedService(); diff --git a/FaKrosnoApi/appsettings.json b/FaKrosnoApi/appsettings.json index 0c30353..a907f3a 100644 --- a/FaKrosnoApi/appsettings.json +++ b/FaKrosnoApi/appsettings.json @@ -1,7 +1,7 @@ { "ConnectionStrings": { - "FaKrosnoConnection": "Server=192.168.0.7;Database=fakrosnotest;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true", - "SytelineSaAppConnection": "Server=192.168.0.7;Database=SL_PRODTEST_SA_APP;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true", + "FaKrosnoConnection": "Server=192.168.0.7;Database=fakrosno;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true", + "SytelineSaAppConnection": "Server=192.168.0.7;Database=SL_PROD_SA_APP;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true", "OrdersManagementConnection": "Server=192.168.0.7;Database=OrdersManagement;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true" }, "Logging": { diff --git a/FaKrosnoEfDataModel/Dtos/ProductDto.cs b/FaKrosnoEfDataModel/Dtos/ProductDto.cs new file mode 100644 index 0000000..6883ce1 --- /dev/null +++ b/FaKrosnoEfDataModel/Dtos/ProductDto.cs @@ -0,0 +1,9 @@ +namespace FaKrosnoEfDataModel.Dtos; + +public class ProductDto : DtoBase +{ + public int ID { get; set; } + public int RecipientID { get; set; } + public string RecipientIdx { get; set; } + public string FaIdx { get; set; } +} \ No newline at end of file diff --git a/FaKrosnoEfDataModel/Entities/Product.cs b/FaKrosnoEfDataModel/Entities/Product.cs new file mode 100644 index 0000000..554a2ac --- /dev/null +++ b/FaKrosnoEfDataModel/Entities/Product.cs @@ -0,0 +1,9 @@ +namespace FaKrosnoEfDataModel.Entities; + +public class Product : EntityBase +{ + public int ID { get; set; } + public int RecipientID { get; set; } + public string RecipientIdx { get; set; } + public string FaIdx { get; set; } +} \ No newline at end of file diff --git a/FaKrosnoEfDataModel/FaKrosnoDbContext.cs b/FaKrosnoEfDataModel/FaKrosnoDbContext.cs index 2e42258..8480b7d 100644 --- a/FaKrosnoEfDataModel/FaKrosnoDbContext.cs +++ b/FaKrosnoEfDataModel/FaKrosnoDbContext.cs @@ -21,7 +21,8 @@ namespace FaKrosnoEfDataModel public DbSet ScheduleOrderDetailDetailMiscs { get; set; } public DbSet ScheduleOrderDetailMiscs { get; set; } public DbSet ScheduleOrderMiscs { get; set; } - + public DbSet Products { get; set; } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { var configuration = new ConfigurationBuilder() @@ -85,6 +86,36 @@ namespace FaKrosnoEfDataModel entity.Property(x => x.QtyDesc).IsRequired(false); entity.Property(x => x.ShipDate).IsRequired(false); }); + + modelBuilder.Entity(entity => + { + entity.ToTable("product"); + + entity.HasKey(e => e.ID); + + entity.Property(e => e.ID) + .HasColumnName("ID") + .ValueGeneratedOnAdd(); + + entity.Property(e => e.RecipientID) + .HasColumnName("recipientID") + .IsRequired(); + + entity.Property(e => e.RecipientIdx) + .HasColumnName("recipientIdx") + .HasMaxLength(50) + .IsRequired(); + + entity.Property(e => e.FaIdx) + .HasColumnName("faIdx") + .HasMaxLength(50) + .IsRequired(); + + // Define the unique constraint for recipientID and recipientIdx + entity.HasIndex(e => new { e.RecipientID, e.RecipientIdx }) + .HasDatabaseName("IX_product") + .IsUnique(); + }); } } } diff --git a/FaKrosnoEfDataModel/MappingProfile.cs b/FaKrosnoEfDataModel/MappingProfile.cs index a0a5ef4..aecabae 100644 --- a/FaKrosnoEfDataModel/MappingProfile.cs +++ b/FaKrosnoEfDataModel/MappingProfile.cs @@ -20,6 +20,7 @@ namespace FaKrosnoEfDataModel CreateMap().IncludeBase() .ReverseMap(); CreateMap().IncludeBase().ReverseMap(); + CreateMap().IncludeBase().ReverseMap(); } } } diff --git a/FaKrosnoEfDataModel/Services/IProductService.cs b/FaKrosnoEfDataModel/Services/IProductService.cs new file mode 100644 index 0000000..643665e --- /dev/null +++ b/FaKrosnoEfDataModel/Services/IProductService.cs @@ -0,0 +1,10 @@ +using FaKrosnoEfDataModel.Dtos; + +namespace FaKrosnoEfDataModel.Services; + +public interface IProductService +{ + Task> GetEntities(); + Task> GetEntitiesToFix(string indexName); + Task UpdateEntity(ProductDto entity); +} \ No newline at end of file diff --git a/FaKrosnoEfDataModel/Services/ProductService.cs b/FaKrosnoEfDataModel/Services/ProductService.cs new file mode 100644 index 0000000..cebdfa2 --- /dev/null +++ b/FaKrosnoEfDataModel/Services/ProductService.cs @@ -0,0 +1,39 @@ +using AutoMapper; +using FaKrosnoEfDataModel.Dtos; +using FaKrosnoEfDataModel.Entities; +using Microsoft.EntityFrameworkCore; + +namespace FaKrosnoEfDataModel.Services; + +public class ProductService : ServiceBase, IProductService +{ + public ProductService(FaKrosnoDbContext context, IMapper mapper) : base(context, mapper) + { + } + + public async Task> GetEntities() + { + IList products = (await GetAll()).ToList(); + + return products; + } + + public async Task> GetEntitiesToFix(string indexName) + { + IList products = (await GetAll()).ToList(); + + return products.Where(x => x?.FaIdx == indexName); + } + + public async Task UpdateEntity(ProductDto entity) + { + Product? product = await Context.Products.FirstOrDefaultAsync(x => x.ID == entity.ID); + + if (product != null) + { + product.FaIdx = entity.FaIdx; + Context.Products.Update(product); + await Context.SaveChangesAsync(); + } + } +} \ No newline at end of file diff --git a/OrdersManagement/Components/Layout/MainLayout.razor b/OrdersManagement/Components/Layout/MainLayout.razor index b4f21e5..f054e55 100644 --- a/OrdersManagement/Components/Layout/MainLayout.razor +++ b/OrdersManagement/Components/Layout/MainLayout.razor @@ -33,6 +33,7 @@ + @* *@ @* *@ @if (UserName == "pkus") diff --git a/OrdersManagement/Components/Pages/Products.razor b/OrdersManagement/Components/Pages/Products.razor new file mode 100644 index 0000000..3ef59a6 --- /dev/null +++ b/OrdersManagement/Components/Pages/Products.razor @@ -0,0 +1,76 @@ +@page "/Products" + +@using Syncfusion.Blazor.Grids +@using Syncfusion.Blazor.Cards +@using Action = Syncfusion.Blazor.Grids.Action +@inject ProductService ProductService +@inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider + +
+ + +

Zarządzanie Indeksami

+
+ + + + + + + + + + + + + + + + + FA Krosno Manager © @(DateTime.Now.Year) + +
+
+@code { + private IEnumerable? _products { get; set; } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + // ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + // + // if (currentUser.Identity?.IsAuthenticated == false) + // { + // NavigationManager.NavigateTo("/Unauthorized"); + // } + // else + // { + await GetProducts(); + + + // } + } + } + + private async Task UserActionComplete(ActionEventArgs args) + { + switch (args.RequestType) + { + case Action.Save: + await ProductService.UpdateProductAsync(args.Data); + await GetProducts(); + break; + } + } + + private async Task GetProducts() + { + _products = await ProductService.GetProductsByIndexAsync("Uzupelnij") ?? new List(); + StateHasChanged(); + } +} \ No newline at end of file diff --git a/OrdersManagement/Program.cs b/OrdersManagement/Program.cs index 53ded2d..1d93dca 100644 --- a/OrdersManagement/Program.cs +++ b/OrdersManagement/Program.cs @@ -13,7 +13,6 @@ var builder = WebApplication.CreateBuilder(args); string faKrosnoApiUrl = builder.Configuration["FaKrosnoApiUrl"] ?? "http://localhost:5001"; builder.Services.AddSyncfusionBlazor(); -builder.Services.AddBlazorBootstrap(); builder.Services.AddBlazoredLocalStorage(); builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) @@ -51,6 +50,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); var app = builder.Build(); diff --git a/OrdersManagement/Services/ProductService.cs b/OrdersManagement/Services/ProductService.cs new file mode 100644 index 0000000..8c66526 --- /dev/null +++ b/OrdersManagement/Services/ProductService.cs @@ -0,0 +1,25 @@ +using FaKrosnoEfDataModel.Dtos; + +namespace OrdersManagement.Services; + +public class ProductService(IHttpClientFactory httpClientFactory, CustomAuthenticationStateProvider authenticationStateProvider) + : ServiceBase(httpClientFactory, authenticationStateProvider) +{ + public async Task?> GetProductsByIndexAsync(string indexName) + { + try + { + return await GetListAsync($"api/Product/by-index?indexName={indexName}"); + } + catch (HttpRequestException ex) + { + Console.WriteLine($"Błąd HTTP w GetProductsByIndexAsync: {ex.Message}"); + return null; + } + } + + public async Task UpdateProductAsync(ProductDto product) + { + return await PutAsJsonAsync("api/Product", product); + } +} \ No newline at end of file