forked from slavaxom9k/PIBD-23_Fomichev_V.S._MagicCarpet
исправление в создании маппера
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using MagicCarpetContracts.DataModels;
|
using MagicCarpetContracts.DataModels;
|
||||||
using MagicCarpetContracts.Exceptions;
|
using MagicCarpetContracts.Exceptions;
|
||||||
|
using MagicCarpetContracts.StoragesContracts;
|
||||||
using MagicCarpetDatabase.Models;
|
using MagicCarpetDatabase.Models;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
@@ -11,7 +12,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace MagicCarpetDatabase.Implementations;
|
namespace MagicCarpetDatabase.Implementations;
|
||||||
|
|
||||||
internal class SaleStorageContract
|
internal class SaleStorageContract : ISaleStorageContract
|
||||||
{
|
{
|
||||||
private readonly MagicCarpetDbContext _dbContext;
|
private readonly MagicCarpetDbContext _dbContext;
|
||||||
private readonly Mapper _mapper;
|
private readonly Mapper _mapper;
|
||||||
@@ -26,15 +27,7 @@ internal class SaleStorageContract
|
|||||||
cfg.CreateMap<Sale, SaleDataModel>();
|
cfg.CreateMap<Sale, SaleDataModel>();
|
||||||
cfg.CreateMap<SaleDataModel, Sale>()
|
cfg.CreateMap<SaleDataModel, Sale>()
|
||||||
.ForMember(x => x.IsCancel, x => x.MapFrom(src => false))
|
.ForMember(x => x.IsCancel, x => x.MapFrom(src => false))
|
||||||
.ForMember(x => x.SaleTours, x => x.MapFrom(src => src.Tours))
|
.ForMember(x => x.SaleTours, x => x.MapFrom(src => src.Tours);
|
||||||
.AfterMap((src, dest) =>
|
|
||||||
{
|
|
||||||
foreach (var tour in dest.SaleTours)
|
|
||||||
{
|
|
||||||
tour.SaleId = dest.Id;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
_mapper = new Mapper(config);
|
_mapper = new Mapper(config);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user