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.
59 lines
2.5 KiB
59 lines
2.5 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 lobbies :
|
|
/// convert model to DTO, model to Entity, ...
|
|
/// and equality protocols
|
|
/// </summary>
|
|
public static class LobbyExtensionMethods
|
|
{
|
|
// conversion methods
|
|
public static Lobby ToModel(this LobbyEntity l)
|
|
=> new Lobby(l.Name, l.Creator.ToModel(), l.Password, l.NbPlayers, l.Id);
|
|
public static Lobby ToModel(this LobbyDto l)
|
|
=> new Lobby(l.Name, l.Creator.ToModel(), l.Password, l.NbPlayers, l.Id);
|
|
public static LobbyDto ToDto(this Lobby l)
|
|
=> new LobbyDto { Id = l.Id, Creator = l.Creator.ToDto(), IdCreator = l.IdCreator,
|
|
Name = l.Name, Password = l.Password, NbPlayers = l.NbPlayers};
|
|
public static LobbyEntity ToEntity(this Lobby l)
|
|
=> new LobbyEntity { Id = l.Id, Creator = l.Creator.ToEntity(), IdCreator = l.IdCreator,
|
|
Name = l.Name, Password = l.Password, NbPlayers = l.NbPlayers};
|
|
|
|
// reuse other methods
|
|
public static LobbyDto ToDto(this LobbyEntity l)
|
|
=> l.ToModel().ToDto();
|
|
public static LobbyEntity ToEntity(this LobbyDto l)
|
|
=> l.ToModel().ToEntity();
|
|
|
|
// equality protocols
|
|
public static bool Equals(this Lobby l1, Lobby l2)
|
|
=> l1.Name == l2.Name && l1.IdCreator == l2.IdCreator;
|
|
|
|
// reuse other methods
|
|
public static bool Equals(this Lobby l1, LobbyDto l2)
|
|
=> l1.Equals(l2.ToModel());
|
|
public static bool Equals(this Lobby l1, LobbyEntity l2)
|
|
=> l1.Equals(l2.ToModel());
|
|
public static bool Equals(this LobbyDto l1, Lobby l2)
|
|
=> l1.ToModel().Equals(l2);
|
|
public static bool Equals(this LobbyDto l1, LobbyDto l2)
|
|
=> l1.ToModel().Equals(l2.ToModel());
|
|
public static bool Equals(this LobbyDto l1, LobbyEntity l2)
|
|
=> l1.ToModel().Equals(l2.ToModel());
|
|
public static bool Equals(this LobbyEntity l1, Lobby l2)
|
|
=> l1.ToModel().Equals(l2);
|
|
public static bool Equals(this LobbyEntity l1, LobbyDto l2)
|
|
=> l1.ToModel().Equals(l2.ToModel());
|
|
public static bool Equals(this LobbyEntity l1, LobbyEntity l2)
|
|
=> l1.ToModel().Equals(l2.ToModel());
|
|
}
|
|
}
|