* Added maintaining Products
* Extended DataModels * Extended API
This commit is contained in:
31
FaKrosnoApi/Controllers/ProductController.cs
Normal file
31
FaKrosnoApi/Controllers/ProductController.cs
Normal file
@@ -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<ActionResult<IEnumerable<ProductDto>>> GetAll()
|
||||||
|
{
|
||||||
|
IEnumerable<ProductDto?> products = await service.GetEntities();
|
||||||
|
return Ok(products);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("by-index")]
|
||||||
|
public async Task<ActionResult<IEnumerable<ProductDto>>> GetByIndex([FromQuery] string indexName)
|
||||||
|
{
|
||||||
|
IEnumerable<ProductDto?> products = await service.GetEntitiesToFix(indexName);
|
||||||
|
return Ok(products);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut]
|
||||||
|
public async Task<ActionResult> Update([FromBody] ProductDto product)
|
||||||
|
{
|
||||||
|
await service.UpdateEntity(product);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -98,6 +98,7 @@ builder.Services.AddScoped<IUserService, UserService>();
|
|||||||
builder.Services.AddScoped<IRoleService, RoleService>();
|
builder.Services.AddScoped<IRoleService, RoleService>();
|
||||||
builder.Services.AddScoped<IFunctionService, FunctionService>();
|
builder.Services.AddScoped<IFunctionService, FunctionService>();
|
||||||
builder.Services.AddScoped<IUserRoleService, UserRoleService>();
|
builder.Services.AddScoped<IUserRoleService, UserRoleService>();
|
||||||
|
builder.Services.AddScoped<IProductService, ProductService>();
|
||||||
|
|
||||||
builder.Services.AddHostedService<TimedHostedService>();
|
builder.Services.AddHostedService<TimedHostedService>();
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"FaKrosnoConnection": "Server=192.168.0.7;Database=fakrosnotest;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_PRODTEST_SA_APP;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"
|
"OrdersManagementConnection": "Server=192.168.0.7;Database=OrdersManagement;User Id=sa;Password=Tetum#2021!;TrustServerCertificate=true"
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
|
|||||||
9
FaKrosnoEfDataModel/Dtos/ProductDto.cs
Normal file
9
FaKrosnoEfDataModel/Dtos/ProductDto.cs
Normal file
@@ -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; }
|
||||||
|
}
|
||||||
9
FaKrosnoEfDataModel/Entities/Product.cs
Normal file
9
FaKrosnoEfDataModel/Entities/Product.cs
Normal file
@@ -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; }
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ namespace FaKrosnoEfDataModel
|
|||||||
public DbSet<ScheduleOrderDetailDetailMisc> ScheduleOrderDetailDetailMiscs { get; set; }
|
public DbSet<ScheduleOrderDetailDetailMisc> ScheduleOrderDetailDetailMiscs { get; set; }
|
||||||
public DbSet<ScheduleOrderDetailMisc> ScheduleOrderDetailMiscs { get; set; }
|
public DbSet<ScheduleOrderDetailMisc> ScheduleOrderDetailMiscs { get; set; }
|
||||||
public DbSet<ScheduleOrderMisc> ScheduleOrderMiscs { get; set; }
|
public DbSet<ScheduleOrderMisc> ScheduleOrderMiscs { get; set; }
|
||||||
|
public DbSet<Product> Products { get; set; }
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
@@ -85,6 +86,36 @@ namespace FaKrosnoEfDataModel
|
|||||||
entity.Property(x => x.QtyDesc).IsRequired(false);
|
entity.Property(x => x.QtyDesc).IsRequired(false);
|
||||||
entity.Property(x => x.ShipDate).IsRequired(false);
|
entity.Property(x => x.ShipDate).IsRequired(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<Product>(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();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace FaKrosnoEfDataModel
|
|||||||
CreateMap<ScheduleOrderDetailMisc, ScheduleOrderDetailMiscDto>().IncludeBase<EntityBase, DtoBase>()
|
CreateMap<ScheduleOrderDetailMisc, ScheduleOrderDetailMiscDto>().IncludeBase<EntityBase, DtoBase>()
|
||||||
.ReverseMap();
|
.ReverseMap();
|
||||||
CreateMap<ScheduleOrderMisc, ScheduleOrderMiscDto>().IncludeBase<EntityBase, DtoBase>().ReverseMap();
|
CreateMap<ScheduleOrderMisc, ScheduleOrderMiscDto>().IncludeBase<EntityBase, DtoBase>().ReverseMap();
|
||||||
|
CreateMap<Product, ProductDto>().IncludeBase<EntityBase, DtoBase>().ReverseMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
FaKrosnoEfDataModel/Services/IProductService.cs
Normal file
10
FaKrosnoEfDataModel/Services/IProductService.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using FaKrosnoEfDataModel.Dtos;
|
||||||
|
|
||||||
|
namespace FaKrosnoEfDataModel.Services;
|
||||||
|
|
||||||
|
public interface IProductService
|
||||||
|
{
|
||||||
|
Task<IEnumerable<ProductDto?>> GetEntities();
|
||||||
|
Task<IEnumerable<ProductDto?>> GetEntitiesToFix(string indexName);
|
||||||
|
Task UpdateEntity(ProductDto entity);
|
||||||
|
}
|
||||||
39
FaKrosnoEfDataModel/Services/ProductService.cs
Normal file
39
FaKrosnoEfDataModel/Services/ProductService.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using FaKrosnoEfDataModel.Dtos;
|
||||||
|
using FaKrosnoEfDataModel.Entities;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace FaKrosnoEfDataModel.Services;
|
||||||
|
|
||||||
|
public class ProductService : ServiceBase<ProductDto>, IProductService
|
||||||
|
{
|
||||||
|
public ProductService(FaKrosnoDbContext context, IMapper mapper) : base(context, mapper)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<ProductDto?>> GetEntities()
|
||||||
|
{
|
||||||
|
IList<ProductDto> products = (await GetAll()).ToList();
|
||||||
|
|
||||||
|
return products;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<ProductDto?>> GetEntitiesToFix(string indexName)
|
||||||
|
{
|
||||||
|
IList<ProductDto> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,6 +33,7 @@
|
|||||||
<SfMenu TValue="MenuItem" HamburgerMode="true" Orientation="Vertical" Title="Menu">
|
<SfMenu TValue="MenuItem" HamburgerMode="true" Orientation="Vertical" Title="Menu">
|
||||||
<MenuItems>
|
<MenuItems>
|
||||||
<MenuItem Text="Zamówienia DELFOR" Url="/" IconCss="fa-solid fa-landmark"></MenuItem>
|
<MenuItem Text="Zamówienia DELFOR" Url="/" IconCss="fa-solid fa-landmark"></MenuItem>
|
||||||
|
<MenuItem Text="Zarządzanie Indeksami" Url="/Products" IconCss="fa-solid fa-basket-shopping"></MenuItem>
|
||||||
@* <MenuItem Text="Zamówienia klienta EDI" Url="/EdiCustomerOrders" IconCss="fa-solid fa-list-check"></MenuItem> *@
|
@* <MenuItem Text="Zamówienia klienta EDI" Url="/EdiCustomerOrders" IconCss="fa-solid fa-list-check"></MenuItem> *@
|
||||||
@* <MenuItem Text="Zamówienia klienta" Url="/CustomerOrders" IconCss="fa-solid fa-database"></MenuItem> *@
|
@* <MenuItem Text="Zamówienia klienta" Url="/CustomerOrders" IconCss="fa-solid fa-database"></MenuItem> *@
|
||||||
@if (UserName == "pkus")
|
@if (UserName == "pkus")
|
||||||
|
|||||||
76
OrdersManagement/Components/Pages/Products.razor
Normal file
76
OrdersManagement/Components/Pages/Products.razor
Normal file
@@ -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
|
||||||
|
|
||||||
|
<div class="h-100 d-flex justify-content-center align-items-start">
|
||||||
|
<SfCard CssClass="shadow" style="width: 100%; max-width: 1200px;">
|
||||||
|
<CardHeader>
|
||||||
|
<h3 class="text-primary">Zarządzanie Indeksami</h3>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<SfGrid DataSource="@_products"
|
||||||
|
AllowPaging="true"
|
||||||
|
ShowColumnMenu="true"
|
||||||
|
Toolbar="@(new List<string> { "Update" })">
|
||||||
|
<GridColumns>
|
||||||
|
<GridColumn Field="@nameof(ProductDto.ID)" AllowEditing="false" IsPrimaryKey="true" HeaderText="ID" Width="70"></GridColumn>
|
||||||
|
<GridColumn Field="@nameof(ProductDto.RecipientID)" AllowEditing="false" HeaderText="Odbiorca" Width="100"></GridColumn>
|
||||||
|
<GridColumn Field="@nameof(ProductDto.RecipientIdx)" AllowEditing="false" HeaderText="Indeks odbiorcy" Width="100"></GridColumn>
|
||||||
|
<GridColumn Field="@nameof(ProductDto.FaIdx)" HeaderText="Kod FA" Width="100"></GridColumn>
|
||||||
|
</GridColumns>
|
||||||
|
<GridEditSettings AllowEditing="true">
|
||||||
|
</GridEditSettings>
|
||||||
|
<GridEvents OnActionComplete="UserActionComplete"
|
||||||
|
TValue="ProductDto">
|
||||||
|
</GridEvents>
|
||||||
|
<GridPageSettings PageSize="10"></GridPageSettings>
|
||||||
|
</SfGrid>
|
||||||
|
</CardContent>
|
||||||
|
<CardFooter>
|
||||||
|
<small class="text-muted">FA Krosno Manager © @(DateTime.Now.Year)</small>
|
||||||
|
</CardFooter>
|
||||||
|
</SfCard>
|
||||||
|
</div>
|
||||||
|
@code {
|
||||||
|
private IEnumerable<ProductDto>? _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<ProductDto> 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<ProductDto>();
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,6 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
string faKrosnoApiUrl = builder.Configuration["FaKrosnoApiUrl"] ?? "http://localhost:5001";
|
string faKrosnoApiUrl = builder.Configuration["FaKrosnoApiUrl"] ?? "http://localhost:5001";
|
||||||
|
|
||||||
builder.Services.AddSyncfusionBlazor();
|
builder.Services.AddSyncfusionBlazor();
|
||||||
builder.Services.AddBlazorBootstrap();
|
|
||||||
builder.Services.AddBlazoredLocalStorage();
|
builder.Services.AddBlazoredLocalStorage();
|
||||||
|
|
||||||
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
@@ -51,6 +50,7 @@ builder.Services.AddScoped<RoleService>();
|
|||||||
builder.Services.AddScoped<FunctionService>();
|
builder.Services.AddScoped<FunctionService>();
|
||||||
builder.Services.AddScoped<UserService>();
|
builder.Services.AddScoped<UserService>();
|
||||||
builder.Services.AddScoped<ErrorLogService>();
|
builder.Services.AddScoped<ErrorLogService>();
|
||||||
|
builder.Services.AddScoped<ProductService>();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
|||||||
25
OrdersManagement/Services/ProductService.cs
Normal file
25
OrdersManagement/Services/ProductService.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using FaKrosnoEfDataModel.Dtos;
|
||||||
|
|
||||||
|
namespace OrdersManagement.Services;
|
||||||
|
|
||||||
|
public class ProductService(IHttpClientFactory httpClientFactory, CustomAuthenticationStateProvider authenticationStateProvider)
|
||||||
|
: ServiceBase<ProductDto>(httpClientFactory, authenticationStateProvider)
|
||||||
|
{
|
||||||
|
public async Task<IEnumerable<ProductDto>?> 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<HttpResponseMessage> UpdateProductAsync(ProductDto product)
|
||||||
|
{
|
||||||
|
return await PutAsJsonAsync("api/Product", product);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user