231 lines
8.3 KiB
C#
231 lines
8.3 KiB
C#
using System;
|
|
using System.Linq.Expressions;
|
|
using Mapster.Models;
|
|
using Netina.Domain.Dtos.LargDtos;
|
|
using Netina.Domain.Dtos.SmallDtos;
|
|
using Netina.Domain.Entities.Comments;
|
|
using Netina.Domain.Entities.Users;
|
|
|
|
namespace Netina.Domain.Mappers
|
|
{
|
|
public static partial class CommentMapper
|
|
{
|
|
public static Comment AdaptToComment(this CommentLDto p1)
|
|
{
|
|
return p1 == null ? null : new Comment()
|
|
{
|
|
Title = p1.Title,
|
|
Content = p1.Content,
|
|
Rate = p1.Rate,
|
|
IsConfirmed = p1.IsConfirmed,
|
|
ParentId = (Guid?)p1.ParentId,
|
|
Parent = new Comment() {Id = p1.ParentId},
|
|
UserId = p1.UserId,
|
|
User = new ApplicationUser() {Id = p1.UserId},
|
|
Id = p1.Id,
|
|
CreatedAt = p1.CreatedAt
|
|
};
|
|
}
|
|
public static Comment AdaptTo(this CommentLDto p2, Comment p3)
|
|
{
|
|
if (p2 == null)
|
|
{
|
|
return null;
|
|
}
|
|
Comment result = p3 ?? new Comment();
|
|
|
|
result.Title = p2.Title;
|
|
result.Content = p2.Content;
|
|
result.Rate = p2.Rate;
|
|
result.IsConfirmed = p2.IsConfirmed;
|
|
result.ParentId = (Guid?)p2.ParentId;
|
|
result.Parent = funcMain1(new Never(), result.Parent, p2);
|
|
result.UserId = p2.UserId;
|
|
result.User = funcMain2(new Never(), result.User, p2);
|
|
result.Id = p2.Id;
|
|
result.CreatedAt = p2.CreatedAt;
|
|
return result;
|
|
|
|
}
|
|
public static Expression<Func<CommentLDto, Comment>> ProjectToComment => p8 => new Comment()
|
|
{
|
|
Title = p8.Title,
|
|
Content = p8.Content,
|
|
Rate = p8.Rate,
|
|
IsConfirmed = p8.IsConfirmed,
|
|
ParentId = (Guid?)p8.ParentId,
|
|
Parent = new Comment() {Id = p8.ParentId},
|
|
UserId = p8.UserId,
|
|
User = new ApplicationUser() {Id = p8.UserId},
|
|
Id = p8.Id,
|
|
CreatedAt = p8.CreatedAt
|
|
};
|
|
public static CommentLDto AdaptToLDto(this Comment p9)
|
|
{
|
|
return p9 == null ? null : new CommentLDto()
|
|
{
|
|
Title = p9.Title,
|
|
Content = p9.Content,
|
|
Rate = p9.Rate,
|
|
IsConfirmed = p9.IsConfirmed,
|
|
ParentId = p9.ParentId == null ? default(Guid) : (Guid)p9.ParentId,
|
|
UserId = p9.UserId,
|
|
UserFullName = p9.User != null ? p9.User.FirstName + " " + p9.User.LastName : string.Empty,
|
|
Id = p9.Id,
|
|
CreatedAt = p9.CreatedAt
|
|
};
|
|
}
|
|
public static CommentLDto AdaptTo(this Comment p10, CommentLDto p11)
|
|
{
|
|
if (p10 == null)
|
|
{
|
|
return null;
|
|
}
|
|
CommentLDto result = p11 ?? new CommentLDto();
|
|
|
|
result.Title = p10.Title;
|
|
result.Content = p10.Content;
|
|
result.Rate = p10.Rate;
|
|
result.IsConfirmed = p10.IsConfirmed;
|
|
result.ParentId = p10.ParentId == null ? default(Guid) : (Guid)p10.ParentId;
|
|
result.UserId = p10.UserId;
|
|
result.UserFullName = p10.User != null ? p10.User.FirstName + " " + p10.User.LastName : string.Empty;
|
|
result.Id = p10.Id;
|
|
result.CreatedAt = p10.CreatedAt;
|
|
return result;
|
|
|
|
}
|
|
public static Expression<Func<Comment, CommentLDto>> ProjectToLDto => p12 => new CommentLDto()
|
|
{
|
|
Title = p12.Title,
|
|
Content = p12.Content,
|
|
Rate = p12.Rate,
|
|
IsConfirmed = p12.IsConfirmed,
|
|
ParentId = p12.ParentId == null ? default(Guid) : (Guid)p12.ParentId,
|
|
UserId = p12.UserId,
|
|
UserFullName = p12.User != null ? p12.User.FirstName + " " + p12.User.LastName : string.Empty,
|
|
Id = p12.Id,
|
|
CreatedAt = p12.CreatedAt
|
|
};
|
|
public static Comment AdaptToComment(this CommentSDto p13)
|
|
{
|
|
return p13 == null ? null : new Comment()
|
|
{
|
|
Title = p13.Title,
|
|
Content = p13.Content,
|
|
IsConfirmed = p13.IsConfirmed,
|
|
IsAdmin = p13.IsAdmin,
|
|
ParentId = (Guid?)p13.ParentId,
|
|
Parent = new Comment() {Id = p13.ParentId},
|
|
UserId = p13.UserId,
|
|
User = new ApplicationUser() {Id = p13.UserId},
|
|
Id = p13.Id,
|
|
CreatedAt = p13.CreatedAt
|
|
};
|
|
}
|
|
public static Comment AdaptTo(this CommentSDto p14, Comment p15)
|
|
{
|
|
if (p14 == null)
|
|
{
|
|
return null;
|
|
}
|
|
Comment result = p15 ?? new Comment();
|
|
|
|
result.Title = p14.Title;
|
|
result.Content = p14.Content;
|
|
result.IsConfirmed = p14.IsConfirmed;
|
|
result.IsAdmin = p14.IsAdmin;
|
|
result.ParentId = (Guid?)p14.ParentId;
|
|
result.Parent = funcMain3(new Never(), result.Parent, p14);
|
|
result.UserId = p14.UserId;
|
|
result.User = funcMain4(new Never(), result.User, p14);
|
|
result.Id = p14.Id;
|
|
result.CreatedAt = p14.CreatedAt;
|
|
return result;
|
|
|
|
}
|
|
public static CommentSDto AdaptToSDto(this Comment p20)
|
|
{
|
|
return p20 == null ? null : new CommentSDto()
|
|
{
|
|
Title = p20.Title,
|
|
Content = p20.Content,
|
|
IsAdmin = p20.IsAdmin,
|
|
IsConfirmed = p20.IsConfirmed,
|
|
ParentId = p20.ParentId == null ? default(Guid) : (Guid)p20.ParentId,
|
|
UserId = p20.UserId,
|
|
UserFullName = p20.User != null ? p20.User.FirstName + " " + p20.User.LastName : string.Empty,
|
|
Id = p20.Id,
|
|
CreatedAt = p20.CreatedAt
|
|
};
|
|
}
|
|
public static CommentSDto AdaptTo(this Comment p21, CommentSDto p22)
|
|
{
|
|
if (p21 == null)
|
|
{
|
|
return null;
|
|
}
|
|
CommentSDto result = p22 ?? new CommentSDto();
|
|
|
|
result.Title = p21.Title;
|
|
result.Content = p21.Content;
|
|
result.IsAdmin = p21.IsAdmin;
|
|
result.IsConfirmed = p21.IsConfirmed;
|
|
result.ParentId = p21.ParentId == null ? default(Guid) : (Guid)p21.ParentId;
|
|
result.UserId = p21.UserId;
|
|
result.UserFullName = p21.User != null ? p21.User.FirstName + " " + p21.User.LastName : string.Empty;
|
|
result.Id = p21.Id;
|
|
result.CreatedAt = p21.CreatedAt;
|
|
return result;
|
|
|
|
}
|
|
public static Expression<Func<Comment, CommentSDto>> ProjectToSDto => p23 => new CommentSDto()
|
|
{
|
|
Title = p23.Title,
|
|
Content = p23.Content,
|
|
IsAdmin = p23.IsAdmin,
|
|
IsConfirmed = p23.IsConfirmed,
|
|
ParentId = p23.ParentId == null ? default(Guid) : (Guid)p23.ParentId,
|
|
UserId = p23.UserId,
|
|
UserFullName = p23.User != null ? p23.User.FirstName + " " + p23.User.LastName : string.Empty,
|
|
Id = p23.Id,
|
|
CreatedAt = p23.CreatedAt
|
|
};
|
|
|
|
private static Comment funcMain1(Never p4, Comment p5, CommentLDto p2)
|
|
{
|
|
Comment result = p5 ?? new Comment();
|
|
|
|
result.Id = p2.ParentId;
|
|
return result;
|
|
|
|
}
|
|
|
|
private static ApplicationUser funcMain2(Never p6, ApplicationUser p7, CommentLDto p2)
|
|
{
|
|
ApplicationUser result = p7 ?? new ApplicationUser();
|
|
|
|
result.Id = p2.UserId;
|
|
return result;
|
|
|
|
}
|
|
|
|
private static Comment funcMain3(Never p16, Comment p17, CommentSDto p14)
|
|
{
|
|
Comment result = p17 ?? new Comment();
|
|
|
|
result.Id = p14.ParentId;
|
|
return result;
|
|
|
|
}
|
|
|
|
private static ApplicationUser funcMain4(Never p18, ApplicationUser p19, CommentSDto p14)
|
|
{
|
|
ApplicationUser result = p19 ?? new ApplicationUser();
|
|
|
|
result.Id = p14.UserId;
|
|
return result;
|
|
|
|
}
|
|
}
|
|
} |