Warehouses #1
62
FaKrosnoApi/Controllers/WzRowMareliController.cs
Normal file
62
FaKrosnoApi/Controllers/WzRowMareliController.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SytelineSaAppEfDataModel.Dtos;
|
||||
using SytelineSaAppEfDataModel.Services;
|
||||
|
||||
namespace FaKrosnoApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class WzRowMareliController(IWzRowMareliService service, IMaterialTransactionService materialTransactionService) : Controller
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<WzRowMareliDto>>> GetAll()
|
||||
{
|
||||
IEnumerable<WzRowMareliDto> wzRows = await service.GetAll();
|
||||
return Ok(wzRows);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> CreateRows([FromBody] IEnumerable<WzRowMareliDto> rows)
|
||||
{
|
||||
if (rows == null || !rows.Any())
|
||||
{
|
||||
return BadRequest("No rows provided.");
|
||||
}
|
||||
|
||||
await service.CreateRows(rows);
|
||||
return CreatedAtAction(nameof(GetAll), new { count = rows.Count() }, rows);
|
||||
}
|
||||
|
||||
[HttpGet("by-wz-header-id")]
|
||||
public async Task<ActionResult<IEnumerable<WzRowMareliDto>>> GetByWzHeaderId(Guid wzHeaderId)
|
||||
{
|
||||
IEnumerable<WzRowMareliDto> wzRows = await service.GetByWzHeaderId(wzHeaderId);
|
||||
return Ok(wzRows);
|
||||
}
|
||||
|
||||
[HttpGet("by-part-number")]
|
||||
public async Task<ActionResult<MaterialTransactionDto>> GetByPartNumber([FromQuery] string partNumber)
|
||||
{
|
||||
MaterialTransactionDto materialTransaction = await materialTransactionService.GetByPartNumber(partNumber);
|
||||
return Ok(materialTransaction);
|
||||
}
|
||||
|
||||
[HttpGet("transactions-with-part-number")]
|
||||
public async Task<ActionResult<MaterialTransactionDto>> GetTransactionsWithPartNumber()
|
||||
{
|
||||
IEnumerable<MaterialTransactionDto> materialTransactions = await materialTransactionService.GetWithPartNumber();
|
||||
return Ok(materialTransactions);
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public async Task<ActionResult> UpdateRows([FromBody] IEnumerable<WzRowMareliDto> rows)
|
||||
{
|
||||
if (rows == null || !rows.Any())
|
||||
{
|
||||
return BadRequest("No rows provided.");
|
||||
}
|
||||
|
||||
await service.UpdateRows(rows);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
@@ -109,6 +109,7 @@ builder.Services.AddScoped<IItemService, ItemService>();
|
||||
builder.Services.AddScoped<IVatCodeAssociationService, VatCodeAssociationService>();
|
||||
builder.Services.AddScoped<IItemCustPriceAllService, ItemCustPriceAllService>();
|
||||
builder.Services.AddScoped<IEdiLogService, EdiLogService>();
|
||||
builder.Services.AddScoped<IWzRowMareliService, WzRowMareliService>();
|
||||
|
||||
builder.Services.AddHostedService<TimedHostedService>();
|
||||
|
||||
|
||||
14
SytelineSaAppEfDataModel/Dtos/WzRowMareliDto.cs
Normal file
14
SytelineSaAppEfDataModel/Dtos/WzRowMareliDto.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace SytelineSaAppEfDataModel.Dtos;
|
||||
|
||||
public class WzRowMareliDto
|
||||
{
|
||||
public Guid ID { get; set; }
|
||||
public Guid? FKHeader { get; set; }
|
||||
public string Type { get; set; }
|
||||
public int? PalletNumber { get; set; }
|
||||
public string ItemNumber { get; set; }
|
||||
public string EngineerNumber { get; set; }
|
||||
public int? Quantity { get; set; }
|
||||
public string OrderNumber { get; set; }
|
||||
public string WzNumber { get; set; }
|
||||
}
|
||||
17
SytelineSaAppEfDataModel/Entities/WzRowMareli.cs
Normal file
17
SytelineSaAppEfDataModel/Entities/WzRowMareli.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace SytelineSaAppEfDataModel.Entities;
|
||||
|
||||
public class WzRowMareli
|
||||
{
|
||||
public Guid ID { get; set; }
|
||||
public Guid? FKHeader { get; set; }
|
||||
public string Type { get; set; }
|
||||
public int? PalletNumber { get; set; }
|
||||
public string ItemNumber { get; set; }
|
||||
public string EngineerNumber { get; set; }
|
||||
public int? Quantity { get; set; }
|
||||
public string OrderNumber { get; set; }
|
||||
public string WzNumber { get; set; }
|
||||
|
||||
// Navigation property
|
||||
public WzHeader Header { get; set; }
|
||||
}
|
||||
@@ -32,6 +32,7 @@ namespace SytelineSaAppEfDataModel
|
||||
CreateMap<VatCodeAssociation, VatCodeAssociationDto>().ReverseMap();
|
||||
CreateMap<ItemCustPriceAll, ItemCustPriceAllDto>().ReverseMap();
|
||||
CreateMap<EdiLog, EdiLogDto>().ReverseMap();
|
||||
CreateMap<WzRowMareli, WzRowMareliDto>().ReverseMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
SytelineSaAppEfDataModel/Services/IWzRowMareliService.cs
Normal file
11
SytelineSaAppEfDataModel/Services/IWzRowMareliService.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using SytelineSaAppEfDataModel.Dtos;
|
||||
|
||||
namespace SytelineSaAppEfDataModel.Services;
|
||||
|
||||
public interface IWzRowMareliService
|
||||
{
|
||||
Task<IEnumerable<WzRowMareliDto>> GetAll();
|
||||
Task CreateRows(IEnumerable<WzRowMareliDto> rows);
|
||||
Task<IEnumerable<WzRowMareliDto>> GetByWzHeaderId(Guid wzHeaderId);
|
||||
Task UpdateRows(IEnumerable<WzRowMareliDto> rows);
|
||||
}
|
||||
36
SytelineSaAppEfDataModel/Services/WzRowMareliService.cs
Normal file
36
SytelineSaAppEfDataModel/Services/WzRowMareliService.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SytelineSaAppEfDataModel.Dtos;
|
||||
using SytelineSaAppEfDataModel.Entities;
|
||||
|
||||
namespace SytelineSaAppEfDataModel.Services;
|
||||
|
||||
public class WzRowMareliService(SytelineSaAppDbContext context, IMapper mapper) : IWzRowMareliService
|
||||
{
|
||||
public async Task<IEnumerable<WzRowMareliDto>> GetAll()
|
||||
{
|
||||
return await context.WzRowsMeyle.Select(x => mapper.Map<WzRowMareliDto>(x)).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task CreateRows(IEnumerable<WzRowMareliDto> rows)
|
||||
{
|
||||
var entities = mapper.Map<IEnumerable<WzRowMareli>>(rows);
|
||||
await context.WzRowsMareli.AddRangeAsync(entities);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<WzRowMareliDto>> GetByWzHeaderId(Guid wzHeaderId)
|
||||
{
|
||||
return await context.WzRowsMareli
|
||||
.Where(x => x.FKHeader == wzHeaderId)
|
||||
.Select(x => mapper.Map<WzRowMareliDto>(x))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task UpdateRows(IEnumerable<WzRowMareliDto> rows)
|
||||
{
|
||||
var entities = mapper.Map<IEnumerable<WzRowMareli>>(rows);
|
||||
context.WzRowsMareli.UpdateRange(entities);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ namespace SytelineSaAppEfDataModel
|
||||
public DbSet<WzClient> WzClients { get; set; }
|
||||
public DbSet<WzHeader> WzHeaders { get; set; }
|
||||
public DbSet<WzRowMeyle> WzRowsMeyle { get; set; }
|
||||
public DbSet<WzRowMareli> WzRowsMareli { get; set; }
|
||||
public DbSet<ItemCust> ItemCusts { get; set; }
|
||||
public DbSet<Lot> Lots { get; set; }
|
||||
public DbSet<EdiCustomerOrderImport> EdiCustomerOrderImports { get; set; }
|
||||
@@ -2506,6 +2507,64 @@ namespace SytelineSaAppEfDataModel
|
||||
.HasColumnType("datetime")
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<WzRowMareli>(entity =>
|
||||
{
|
||||
entity.ToTable("wz_row_mareli");
|
||||
|
||||
entity.HasKey(e => e.ID);
|
||||
|
||||
entity.Property(e => e.ID)
|
||||
.HasColumnName("ID")
|
||||
.HasColumnType("uniqueidentifier")
|
||||
.IsRequired();
|
||||
|
||||
entity.Property(e => e.FKHeader)
|
||||
.HasColumnName("FK_Header")
|
||||
.HasColumnType("uniqueidentifier")
|
||||
.IsRequired(false);
|
||||
|
||||
entity.Property(e => e.Type)
|
||||
.HasColumnName("type")
|
||||
.HasMaxLength(30)
|
||||
.IsRequired(false);
|
||||
|
||||
entity.Property(e => e.PalletNumber)
|
||||
.HasColumnName("pallet_number")
|
||||
.HasColumnType("int")
|
||||
.IsRequired(false);
|
||||
|
||||
entity.Property(e => e.ItemNumber)
|
||||
.HasColumnName("item_number")
|
||||
.HasMaxLength(50)
|
||||
.IsRequired(false);
|
||||
|
||||
entity.Property(e => e.EngineerNumber)
|
||||
.HasColumnName("engineer_number")
|
||||
.HasMaxLength(50)
|
||||
.IsRequired(false);
|
||||
|
||||
entity.Property(e => e.Quantity)
|
||||
.HasColumnName("quantity")
|
||||
.HasColumnType("int")
|
||||
.IsRequired(false);
|
||||
|
||||
entity.Property(e => e.OrderNumber)
|
||||
.HasColumnName("order_number")
|
||||
.HasMaxLength(50)
|
||||
.IsRequired(false);
|
||||
|
||||
entity.Property(e => e.WzNumber)
|
||||
.HasColumnName("wz_number")
|
||||
.HasMaxLength(50)
|
||||
.IsRequired(false);
|
||||
|
||||
// Foreign Key
|
||||
entity.HasOne(e => e.Header)
|
||||
.WithMany()
|
||||
.HasForeignKey(e => e.FKHeader)
|
||||
.HasConstraintName("wz_row_mareli_wz_header_ID_fk");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user