* Added maintaining Products
* Extended DataModels * Extended API
This commit is contained in:
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,7 +21,8 @@ namespace FaKrosnoEfDataModel
|
||||
public DbSet<ScheduleOrderDetailDetailMisc> ScheduleOrderDetailDetailMiscs { get; set; }
|
||||
public DbSet<ScheduleOrderDetailMisc> ScheduleOrderDetailMiscs { get; set; }
|
||||
public DbSet<ScheduleOrderMisc> ScheduleOrderMiscs { get; set; }
|
||||
|
||||
public DbSet<Product> 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<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>()
|
||||
.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user