* Extended of Dtos
* Added new Services and Controllers
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SytelineSaAppEfDataModel.Dtos;
|
||||
using SytelineSaAppEfDataModel.Services;
|
||||
|
||||
namespace FaKrosnoApi.Controllers;
|
||||
@@ -13,4 +14,22 @@ public class EdiCustomerOrderImportController(IEdiCustomerOrderImportService ser
|
||||
DateTime lastUpdateDate = await service.GetLastUpdateDate();
|
||||
return Ok(lastUpdateDate);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> Add([FromBody] EdiCustomerOrderImportDto ediCustomerOrderImport)
|
||||
{
|
||||
var result = await service.AddEdiCustomerOrderImport(ediCustomerOrderImport);
|
||||
return result
|
||||
? Ok("Utworzono rekord w tabeli EdiCustomerOrderImport.")
|
||||
: BadRequest($"Nie mogę utworzyć rekordu w tabeli EdiCustomerOrderImport.");
|
||||
}
|
||||
|
||||
[HttpPost("add-bulk")]
|
||||
public async Task<ActionResult> Add([FromBody] IList<EdiCustomerOrderImportDto> ediCustomerOrderImports)
|
||||
{
|
||||
var result = await service.AddEdiCustomerOrderImports(ediCustomerOrderImports);
|
||||
return result
|
||||
? Ok("Utworzono rekordy w tabeli EdiCustomerOrderImport.")
|
||||
: BadRequest($"Nie mogę utworzyć rekordów w tabeli EdiCustomerOrderImport.");
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ namespace FaKrosnoApi.Controllers
|
||||
var result = await service.SaveOrdersWithDetails(ediCustomerOrders);
|
||||
|
||||
return result.Item1
|
||||
? Ok("Orders saved successfully.")
|
||||
? Ok(result)
|
||||
: BadRequest($"Failed to save orders. Error: {result.Item2}");
|
||||
}
|
||||
}
|
||||
|
||||
19
FaKrosnoApi/Controllers/EdiLogController.cs
Normal file
19
FaKrosnoApi/Controllers/EdiLogController.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SytelineSaAppEfDataModel.Dtos;
|
||||
using SytelineSaAppEfDataModel.Services;
|
||||
|
||||
namespace FaKrosnoApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class EdiLogController(IEdiLogService service) : Controller
|
||||
{
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> Add([FromBody] EdiLogDto ediLog)
|
||||
{
|
||||
var result = await service.AddEdiLog(ediLog);
|
||||
return result
|
||||
? Ok("Utworzono rekord w tabeli EdiLog.")
|
||||
: BadRequest($"Nie mogę utworzyć rekordu w tabeli EdiLog.");
|
||||
}
|
||||
}
|
||||
@@ -66,19 +66,19 @@ builder.Services.AddOpenApiDocument(config =>
|
||||
config.OperationProcessors.Add(new OperationSecurityScopeProcessor("Bearer"));
|
||||
});
|
||||
|
||||
// builder.Services.AddHangfire(config => config
|
||||
// .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
|
||||
// .UseSimpleAssemblyNameTypeSerializer()
|
||||
// .UseRecommendedSerializerSettings()
|
||||
// .UseSqlServerStorage(builder.Configuration.GetConnectionString("OrdersManagementConnection"), new SqlServerStorageOptions
|
||||
// {
|
||||
// CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
|
||||
// SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
|
||||
// QueuePollInterval = TimeSpan.Zero,
|
||||
// UseRecommendedIsolationLevel = true,
|
||||
// DisableGlobalLocks = true
|
||||
// }));
|
||||
// builder.Services.AddHangfireServer();
|
||||
builder.Services.AddHangfire(config => config
|
||||
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
|
||||
.UseSimpleAssemblyNameTypeSerializer()
|
||||
.UseRecommendedSerializerSettings()
|
||||
.UseSqlServerStorage(builder.Configuration.GetConnectionString("OrdersManagementConnection"), new SqlServerStorageOptions
|
||||
{
|
||||
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
|
||||
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
|
||||
QueuePollInterval = TimeSpan.Zero,
|
||||
UseRecommendedIsolationLevel = true,
|
||||
DisableGlobalLocks = true
|
||||
}));
|
||||
builder.Services.AddHangfireServer();
|
||||
|
||||
builder.Services.AddAutoMapper(typeof(FaKrosnoMappingProfile), typeof(SytelineSaAppMappingProfile),
|
||||
typeof(OrdersManagementMappingProfile));
|
||||
@@ -108,6 +108,7 @@ builder.Services.AddScoped<ICustomerTpService, CustomerTpService>();
|
||||
builder.Services.AddScoped<IItemService, ItemService>();
|
||||
builder.Services.AddScoped<IVatCodeAssociationService, VatCodeAssociationService>();
|
||||
builder.Services.AddScoped<IItemCustPriceAllService, ItemCustPriceAllService>();
|
||||
builder.Services.AddScoped<IEdiLogService, EdiLogService>();
|
||||
|
||||
builder.Services.AddHostedService<TimedHostedService>();
|
||||
|
||||
@@ -125,6 +126,6 @@ app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
//app.UseHangfireDashboard();
|
||||
app.UseHangfireDashboard();
|
||||
|
||||
app.Run();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"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",
|
||||
"SytelineSaAppConnection": "Server=192.168.0.7;Database=SL_PRODTEST_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": {
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper.Configuration.Annotations;
|
||||
|
||||
namespace SytelineSaAppEfDataModel.Dtos
|
||||
{
|
||||
@@ -105,6 +106,8 @@ namespace SytelineSaAppEfDataModel.Dtos
|
||||
public string TranslatedStatus => TranslateStatus(Status ?? string.Empty);
|
||||
public string? SlOrderNumber => EdiCustomerOrderTranslates.MaxBy(x => x.CreatedDate)?.CoCoNum;
|
||||
public string SentToSl => Posted == 1 ? "TAK" : "NIE";
|
||||
[Ignore] public int ScheduleOrderId { get; set; }
|
||||
[Ignore] public DateTime LastUpdateDate { get; set; }
|
||||
|
||||
public IEnumerable<EdiCustomerOrderLineDto> EdiCustomerOrderLines { get; set; } = new List<EdiCustomerOrderLineDto>();
|
||||
public IEnumerable<EdiCustomerOrderTranslateDto> EdiCustomerOrderTranslates { get; set; } = new List<EdiCustomerOrderTranslateDto>();
|
||||
|
||||
11
SytelineSaAppEfDataModel/Dtos/EdiLogDto.cs
Normal file
11
SytelineSaAppEfDataModel/Dtos/EdiLogDto.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace SytelineSaAppEfDataModel.Dtos;
|
||||
|
||||
public class EdiLogDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ProcessName { get; set; }
|
||||
public string ConfigurationName { get; set; }
|
||||
public int Status { get; set; }
|
||||
public string LogText { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
}
|
||||
11
SytelineSaAppEfDataModel/Entities/EdiLog.cs
Normal file
11
SytelineSaAppEfDataModel/Entities/EdiLog.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace SytelineSaAppEfDataModel.Entities;
|
||||
|
||||
public class EdiLog
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ProcessName { get; set; }
|
||||
public string ConfigurationName { get; set; }
|
||||
public int Status { get; set; }
|
||||
public string LogText { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
}
|
||||
@@ -31,6 +31,7 @@ namespace SytelineSaAppEfDataModel
|
||||
CreateMap<Item, ItemDto>().ReverseMap();
|
||||
CreateMap<VatCodeAssociation, VatCodeAssociationDto>().ReverseMap();
|
||||
CreateMap<ItemCustPriceAll, ItemCustPriceAllDto>().ReverseMap();
|
||||
CreateMap<EdiLog, EdiLogDto>().ReverseMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SytelineSaAppEfDataModel.Dtos;
|
||||
using SytelineSaAppEfDataModel.Entities;
|
||||
|
||||
namespace SytelineSaAppEfDataModel.Services;
|
||||
|
||||
@@ -10,4 +12,18 @@ public class EdiCustomerOrderImportService(SytelineSaAppDbContext context, IMapp
|
||||
return (await context.EdiCustomerOrderImports.OrderByDescending(x => x.LastUpdateDate)
|
||||
.FirstOrDefaultAsync())?.LastUpdateDate ?? DateTime.Now.Date;
|
||||
}
|
||||
|
||||
public async Task<bool> AddEdiCustomerOrderImport(EdiCustomerOrderImportDto ediCustomerOrderImport)
|
||||
{
|
||||
var entity = mapper.Map<EdiCustomerOrderImport>(ediCustomerOrderImport);
|
||||
await context.EdiCustomerOrderImports.AddAsync(entity);
|
||||
return await context.SaveChangesAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> AddEdiCustomerOrderImports(IList<EdiCustomerOrderImportDto> ediCustomerOrderImports)
|
||||
{
|
||||
var entities = mapper.Map<List<EdiCustomerOrderImport>>(ediCustomerOrderImports);
|
||||
context.EdiCustomerOrderImports.AddRange(entities);
|
||||
return await context.SaveChangesAsync() > 0;
|
||||
}
|
||||
}
|
||||
@@ -149,13 +149,16 @@ namespace SytelineSaAppEfDataModel.Services
|
||||
|
||||
try
|
||||
{
|
||||
await context.EdiCustomerOrders.AddRangeAsync(ediCustomerOrders.Select(mapper.Map<EdiCustomerOrder>));
|
||||
await context.EdiCustomerOrderLines.AddRangeAsync(ediCustomerOrders
|
||||
.SelectMany(x => x.EdiCustomerOrderLines)
|
||||
.Select(mapper.Map<EdiCustomerOrderLine>));
|
||||
await context.EdiCustomerOrderLineItems.AddRangeAsync(ediCustomerOrders
|
||||
.SelectMany(x => x.EdiCustomerOrderLines)
|
||||
.SelectMany(y => y.EdiCustomerOrderLineItems).Select(mapper.Map<EdiCustomerOrderLineItem>));
|
||||
IList<EdiCustomerOrder> customerOrders = ediCustomerOrders.Select(mapper.Map<EdiCustomerOrder>).ToList();
|
||||
IList<EdiCustomerOrderLine> ediCustomerOrderLines = ediCustomerOrders
|
||||
.SelectMany(x => x.EdiCustomerOrderLines).Select(mapper.Map<EdiCustomerOrderLine>).ToList();
|
||||
IList<EdiCustomerOrderLineItem> ediCustomerOrderLineItems = ediCustomerOrders
|
||||
.SelectMany(x => x.EdiCustomerOrderLines).SelectMany(y => y.EdiCustomerOrderLineItems)
|
||||
.Select(mapper.Map<EdiCustomerOrderLineItem>).ToList();
|
||||
|
||||
await context.EdiCustomerOrders.AddRangeAsync(customerOrders);
|
||||
await context.EdiCustomerOrderLines.AddRangeAsync(ediCustomerOrderLines);
|
||||
await context.EdiCustomerOrderLineItems.AddRangeAsync(ediCustomerOrderLineItems);
|
||||
await context.EdiCustomerOrderTranslates.AddRangeAsync(ediCustomerOrders
|
||||
.SelectMany(x => x.EdiCustomerOrderTranslates)
|
||||
.Select(mapper.Map<EdiCustomerOrderTranslate>));
|
||||
|
||||
15
SytelineSaAppEfDataModel/Services/EdiLogService.cs
Normal file
15
SytelineSaAppEfDataModel/Services/EdiLogService.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using AutoMapper;
|
||||
using SytelineSaAppEfDataModel.Dtos;
|
||||
using SytelineSaAppEfDataModel.Entities;
|
||||
|
||||
namespace SytelineSaAppEfDataModel.Services;
|
||||
|
||||
public class EdiLogService(SytelineSaAppDbContext context, IMapper mapper) : IEdiLogService
|
||||
{
|
||||
public async Task<bool> AddEdiLog(EdiLogDto ediLog)
|
||||
{
|
||||
var entity = mapper.Map<EdiLog>(ediLog);
|
||||
await context.EdiLogs.AddAsync(entity);
|
||||
return await context.SaveChangesAsync() > 0;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
using SytelineSaAppEfDataModel.Dtos;
|
||||
|
||||
namespace SytelineSaAppEfDataModel.Services;
|
||||
|
||||
public interface IEdiCustomerOrderImportService
|
||||
{
|
||||
Task<DateTime> GetLastUpdateDate();
|
||||
Task<bool> AddEdiCustomerOrderImport(EdiCustomerOrderImportDto ediCustomerOrderImport);
|
||||
Task<bool> AddEdiCustomerOrderImports(IList<EdiCustomerOrderImportDto> ediCustomerOrderImports);
|
||||
}
|
||||
8
SytelineSaAppEfDataModel/Services/IEdiLogService.cs
Normal file
8
SytelineSaAppEfDataModel/Services/IEdiLogService.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using SytelineSaAppEfDataModel.Dtos;
|
||||
|
||||
namespace SytelineSaAppEfDataModel.Services;
|
||||
|
||||
public interface IEdiLogService
|
||||
{
|
||||
Task<bool> AddEdiLog(EdiLogDto ediLog);
|
||||
}
|
||||
@@ -30,6 +30,7 @@ namespace SytelineSaAppEfDataModel
|
||||
public DbSet<Item> Items { get; set; }
|
||||
public DbSet<VatCodeAssociation> VatCodeAssociations { get; set; }
|
||||
public DbSet<ItemCustPriceAll> ItemCustPriceAlls { get; set; }
|
||||
public DbSet<EdiLog> EdiLogs { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
@@ -2468,6 +2469,43 @@ namespace SytelineSaAppEfDataModel
|
||||
.HasDatabaseName("IX_itemcustprice_all_RowPointer")
|
||||
.IsUnique();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<EdiLog>(entity =>
|
||||
{
|
||||
entity.ToTable("edi_logs");
|
||||
|
||||
entity.HasKey(e => e.Id);
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.HasColumnName("Id")
|
||||
.HasColumnType("int")
|
||||
.IsRequired();
|
||||
|
||||
entity.Property(e => e.ProcessName)
|
||||
.HasColumnName("ProcessName")
|
||||
.HasMaxLength(200)
|
||||
.IsRequired();
|
||||
|
||||
entity.Property(e => e.ConfigurationName)
|
||||
.HasColumnName("ConfigurationName")
|
||||
.HasMaxLength(200)
|
||||
.IsRequired();
|
||||
|
||||
entity.Property(e => e.Status)
|
||||
.HasColumnName("Status")
|
||||
.HasColumnType("int")
|
||||
.IsRequired();
|
||||
|
||||
entity.Property(e => e.LogText)
|
||||
.HasColumnName("LogText")
|
||||
.HasColumnType("varchar(max)")
|
||||
.IsRequired();
|
||||
|
||||
entity.Property(e => e.Date)
|
||||
.HasColumnName("Date")
|
||||
.HasColumnType("datetime")
|
||||
.IsRequired();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user