using AutoMapper; using MTWireGuard.Application.Models.Mikrotik; using MTWireGuard.Application.Models.Models.Responses; using MTWireGuard.Application.Models.Requests; using MTWireGuard.Application.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using MikrotikAPI.Models; namespace MTWireGuard.Application.Mapper { public class RequestProfile : Profile { public RequestProfile() { // Peer Request CreateMap() .ForMember(dest => dest.Disabled, opt => opt.MapFrom(src => !src.Enabled)) .ForMember(dest => dest.EndpointAddress, opt => opt.MapFrom(src => src.Endpoint)) .ForMember(dest => dest.PersistentKeepalive, opt => opt.MapFrom(src => src.KeepAlive.ToString())) .ForMember(dest => dest.Expire, opt => opt.MapFrom(src => (!string.IsNullOrWhiteSpace(src.Expire)) ? Convert.ToDateTime(src.Expire) : (DateTime?)null)); CreateMap(); CreateMap() .ForMember(dest => dest.EndpointAddress, opt => opt.MapFrom(src => src.Endpoint)) .ForMember(dest => dest.PersistentKeepalive, opt => opt.MapFrom(src => src.KeepAlive)) .ForMember(dest => dest.Expire, opt => opt.MapFrom(src => Convert.ToDateTime(src.Expire))); // Server Request CreateMap() .ForMember(dest => dest.ListenPort, opt => opt.MapFrom(src => src.Port)); CreateMap() .ForMember(dest => dest.ListenPort, opt => opt.MapFrom(src => src.Port)); // IP Pool Request CreateMap() .ForMember(dest => dest.Ranges, opt => opt.MapFrom(src => string.Join(',', src.Ranges))); CreateMap() .ForMember(dest => dest.Id, opt => opt.MapFrom(src => $"*{src.Id:X}")) .ForMember(dest => dest.Ranges, opt => opt.MapFrom(src => string.Join(',', src.Ranges))); // IP Pool Create Model CreateMap() .ForMember(dest => dest.NextPool, opt => opt.MapFrom(src => src.Next)); // IP Pool Update Model CreateMap() .ForMember(dest => dest.NextPool, opt => opt.MapFrom(src => src.Next)); // Item Creation CreateMap() .ForMember(dest => dest.Code, opt => opt.MapFrom(src => (src.Success) ? "200" : src.Code.ToString())) .ForMember(dest => dest.Title, opt => opt.MapFrom(src => (src.Success) ? "Done" : src.Message)) .ForMember(dest => dest.Description, opt => opt.MapFrom(src => (src.Success) ? "Item created/updated successfully." : src.Detail)); // Toast Result CreateMap() .ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.Code == "200" ? src.Title : $"[{src.Code}] {src.Title}")) .ForMember(dest => dest.Body, opt => opt.MapFrom(src => src.Description)) .ForMember(dest => dest.Background, opt => opt.MapFrom(src => src.Code == "200" ? "success" : "danger")); } } }