You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.2 KiB
58 lines
2.2 KiB
using DTOs;
|
|
using Entities;
|
|
using Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ExtensionsClassLibrairie
|
|
{
|
|
/// <summary>
|
|
/// define some methods to manipulate entity, model and dto chapters :
|
|
/// convert model to DTO, model to Entity, ...
|
|
/// and equality protocols
|
|
/// </summary>
|
|
public static class ChapterExtensionMethods
|
|
{
|
|
// conversion methods
|
|
public static Chapter ToModel(this ChapterEntity c)
|
|
=> new Chapter(c.Name, c.Id);
|
|
public static Chapter ToModel(this ChapterDto c)
|
|
=> new Chapter(c.Name, c.Id);
|
|
public static ChapterDto ToDto(this Chapter c)
|
|
=> new ChapterDto { Id = c.Id, Name = c.Name };
|
|
public static ChapterEntity ToEntity(this Chapter c)
|
|
=> new ChapterEntity { Id = c.Id, Name = c.Name };
|
|
|
|
// reuse other methods
|
|
public static ChapterDto ToDto(this ChapterEntity c)
|
|
=> c.ToModel().ToDto();
|
|
public static ChapterEntity ToEntity(this ChapterDto c)
|
|
=> c.ToModel().ToEntity();
|
|
|
|
// equality protocols
|
|
public static bool Equals(this Chapter c1, Chapter c2)
|
|
=> c1.Name == c2.Name;
|
|
|
|
// reuse other methods
|
|
public static bool Equals(this Chapter c1, ChapterDto c2)
|
|
=> c1.Equals(c2.ToModel());
|
|
public static bool Equals(this Chapter c1, ChapterEntity c2)
|
|
=> c1.Equals(c2.ToModel());
|
|
public static bool Equals(this ChapterDto c1, Chapter c2)
|
|
=> c1.ToModel().Equals(c2);
|
|
public static bool Equals(this ChapterDto c1, ChapterDto c2)
|
|
=> c1.ToModel().Equals(c2.ToModel());
|
|
public static bool Equals(this ChapterDto c1, ChapterEntity c2)
|
|
=> c1.ToModel().Equals(c2.ToModel());
|
|
public static bool Equals(this ChapterEntity c1, Chapter c2)
|
|
=> c1.ToModel().Equals(c2);
|
|
public static bool Equals(this ChapterEntity c1, ChapterDto c2)
|
|
=> c1.ToModel().Equals(c2.ToModel());
|
|
public static bool Equals(this ChapterEntity c1, ChapterEntity c2)
|
|
=> c1.ToModel().Equals(c2.ToModel());
|
|
}
|
|
}
|