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.
3.01-QCM_MuscuMaths/WebApi/ExtensionsClassLibrairie/ChapterExtensionMethods.cs

36 lines
1.1 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();
}
}