65 lines
2.2 KiB
C#
65 lines
2.2 KiB
C#
using AutobusApi.Application.Common.Mappings;
|
|
using AutobusApi.Domain.Entities;
|
|
using AutoMapper;
|
|
|
|
namespace AutobusApi.Application.Routes.Queries;
|
|
|
|
public class RouteDto : IMapFrom<Route>
|
|
{
|
|
public int Id { get; set; }
|
|
|
|
public List<RouteAddressDto> Addresses { get; set; } = null!;
|
|
|
|
public void Mapping(Profile profile)
|
|
{
|
|
profile.CreateMap<Route, RouteDto>()
|
|
.ForMember(d => d.Addresses, opt => opt.MapFrom(s => s.RouteAddresses));
|
|
}
|
|
}
|
|
|
|
public class RouteAddressDto : IMapFrom<RouteAddress>
|
|
{
|
|
public int Id { get; set; }
|
|
|
|
public string Name { get; set; } = null!;
|
|
|
|
public int Order { get; set; }
|
|
|
|
public double Latitude { get; set; }
|
|
|
|
public double Longitude { get; set; }
|
|
|
|
public string VehicleType { get; set; } = null!;
|
|
|
|
public int RouteAddressId { get; set; }
|
|
|
|
public int CityId { get; set; }
|
|
|
|
public string CityName { get; set; } = null!;
|
|
|
|
public int RegionId { get; set; }
|
|
|
|
public string RegionName { get; set; } = null!;
|
|
|
|
public int CountryId { get; set; }
|
|
|
|
public string CountryName { get; set; } = null!;
|
|
|
|
public void Mapping(Profile profile)
|
|
{
|
|
profile.CreateMap<RouteAddress, RouteAddressDto>()
|
|
.ForMember(d => d.Id, opt => opt.MapFrom(s => s.AddressId))
|
|
.ForMember(d => d.Name, opt => opt.MapFrom(s => s.Address.Name))
|
|
.ForMember(d => d.RouteAddressId, opt => opt.MapFrom(s => s.Id))
|
|
.ForMember(d => d.CityId, opt => opt.MapFrom(s => s.Address.CityId))
|
|
.ForMember(d => d.CityName, opt => opt.MapFrom(s => s.Address.City.Name))
|
|
.ForMember(d => d.RegionId, opt => opt.MapFrom(s => s.Address.City.RegionId))
|
|
.ForMember(d => d.RegionName, opt => opt.MapFrom(s => s.Address.City.Region.Name))
|
|
.ForMember(d => d.CountryId, opt => opt.MapFrom(s => s.Address.City.Region.CountryId))
|
|
.ForMember(d => d.CountryName, opt => opt.MapFrom(s => s.Address.City.Region.Country.Name))
|
|
.ForMember(d => d.Latitude, opt => opt.MapFrom(s => s.Address.Location.Latitude))
|
|
.ForMember(d => d.Longitude, opt => opt.MapFrom(s => s.Address.Location.Longitude))
|
|
.ForMember(d => d.VehicleType, opt => opt.MapFrom(s => s.Address.VehicleType.ToString()));
|
|
}
|
|
}
|