classlib/ExpenseTracker.Application/Transactions/TransactionJsonDto.cs
2024-08-07 21:12:02 +03:00

26 lines
762 B
C#

using AutoMapper;
using ExpenseTracker.Application.Common.Mappings;
using ExpenseTracker.Domain.Entities;
namespace ExpenseTracker.Application.Transactions;
public class TransactionJsonDto : IMapFrom<Transaction>
{
public double Amount { get; set; }
public string Category { get; set; }
public DateTimeOffset Time { get; set; }
public string? Description { get; set; }
public void Mapping(Profile profile)
{
profile.CreateMap<Transaction, TransactionJsonDto>()
.ForMember(d => d.Category, opt => opt.MapFrom(s => s.Category.Name));
profile.CreateMap<TransactionJsonDto, Transaction>()
.ForMember(d => d.Category, opt => opt.MapFrom(s => Domain.Enums.Category.FromName(s.Category)));
}
}