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.
288 lines
9.8 KiB
288 lines
9.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Entity;
|
|
using DTO;
|
|
using System.Reflection.Metadata;
|
|
|
|
namespace Dto2Entities
|
|
{
|
|
public static class Extention
|
|
{
|
|
// --------------------------- ToDto --------------------------- \\
|
|
|
|
public static CharacterDTO ToDto(this Character item)
|
|
{
|
|
CharacterDTO character = new CharacterDTO();
|
|
character.Id = item.Id;
|
|
character.Name = item.Name;
|
|
character.imagePath = item.Images.ImgPath;
|
|
return character;
|
|
}
|
|
|
|
public static CommentaryDTO ToDto(this Commentary item)
|
|
{
|
|
CommentaryDTO commentary = new CommentaryDTO();
|
|
commentary.Id = item.Id;
|
|
commentary.Date = item.DateCommentary;
|
|
commentary.Comment = item.Comment;
|
|
commentary.User = item.User.UserName;
|
|
commentary.ImagePath = item.User.Images.ImgPath;
|
|
return commentary;
|
|
}
|
|
|
|
// Surement a refaire car Faoirite Entity modifier sur branche EF
|
|
public static FavoriteDTO ToDto(this Favorite item)
|
|
{
|
|
FavoriteDTO favorite = new FavoriteDTO();
|
|
favorite.IdUser = item.IdUsers;
|
|
favorite.IdQuote = item.IdQuote;
|
|
return favorite;
|
|
}
|
|
|
|
public static ImageDTO ToDto(this Images item)
|
|
{
|
|
ImageDTO image = new ImageDTO();
|
|
image.IdImage = item.Id;
|
|
image.ImagePath = item.ImgPath;
|
|
return image;
|
|
}
|
|
|
|
public static QuestionDTO ToDto(this Question item)
|
|
{
|
|
QuestionDTO question = new QuestionDTO();
|
|
question.Id = item.Id;
|
|
question.Question = item.Text;
|
|
question.AnswerA = item.AnswerA;
|
|
question.AnswerB = item.AnswerB;
|
|
question.AnswerC = item.AnswerC;
|
|
question.AnswerD = item.AnswerD;
|
|
question.CorrectAnswer = item.CorrectAnswer;
|
|
return question;
|
|
}
|
|
|
|
public static QuizDTO ToDto(this Quiz item)
|
|
{
|
|
QuizDTO quiz = new QuizDTO();
|
|
quiz.Id = item.Id;
|
|
quiz.NbQuestion = item.NbQuestion;
|
|
quiz.Title = item.Title;
|
|
quiz.ImagePath = item.Images.ImgPath;
|
|
return quiz;
|
|
}
|
|
|
|
// Surement a refaire car QuizQuestion Entity modifier sur branche EF
|
|
public static QuizQuestionDTO ToDto(this QuizQuestion item)
|
|
{
|
|
QuizQuestionDTO quizQuestion = new QuizQuestionDTO();
|
|
quizQuestion.IdQuiz = item.IdQuiz;
|
|
quizQuestion.IdQuestion = item.IdQuestion;
|
|
return quizQuestion;
|
|
}
|
|
|
|
public static QuoteDTO ToDto(this Quote item)
|
|
{
|
|
QuoteDTO quote = new QuoteDTO();
|
|
quote.Id = item.Id;
|
|
quote.Content = item.Content;
|
|
quote.DateSource = item.Source.Year;
|
|
quote.Character = item.Character.Name;
|
|
quote.TitleSource = item.Source.Title;
|
|
quote.Langage = item.Langage.ToDto();
|
|
quote.ImagePath = item.Character.Images.ImgPath;
|
|
quote.Like = item.Likes;
|
|
quote.Type = item.Source.TypeSrc.ToDto();
|
|
return quote;
|
|
}
|
|
|
|
public static SourceDTO ToDto(this Source item)
|
|
{
|
|
SourceDTO source = new SourceDTO();
|
|
source.Id = item.Id;
|
|
source.Date = item.Year;
|
|
source.Title = item.Title;
|
|
source.Type = item.TypeSrc.ToDto();
|
|
return source;
|
|
}
|
|
|
|
public static UserDTO ToDto(this Users item)
|
|
{
|
|
UserDTO user = new UserDTO();
|
|
user.Id = item.Id;
|
|
user.Pseudo = item.UserName;
|
|
user.Password = item.Password;
|
|
user.Email = item.Email;
|
|
user.date = item.Created;
|
|
user.ImageProfil = item.Images.ImgPath;
|
|
return user;
|
|
}
|
|
|
|
public static List<UserDTO> ToDto(this List<Users> users)
|
|
{
|
|
List<UserDTO> userDTOs = new List<UserDTO>();
|
|
foreach (Users user in users)
|
|
{
|
|
userDTOs.Add(ToDto(user));
|
|
}
|
|
return userDTOs;
|
|
}
|
|
|
|
public static TypeLangageDTO ToDto(this LangEnum item)
|
|
{
|
|
switch (item)
|
|
{
|
|
case LangEnum.vf: return TypeLangageDTO.vf;
|
|
case LangEnum.vo: return TypeLangageDTO.vo;
|
|
case LangEnum.ve: return TypeLangageDTO.ve;
|
|
default: return TypeLangageDTO.vo;
|
|
}
|
|
}
|
|
|
|
public static TypeSrcEnumDTO ToDto(this TypeSrcEnum item)
|
|
{
|
|
switch (item)
|
|
{
|
|
case TypeSrcEnum.movie: return TypeSrcEnumDTO.movie;
|
|
case TypeSrcEnum.book: return TypeSrcEnumDTO.book;
|
|
case TypeSrcEnum.series: return TypeSrcEnumDTO.serie;
|
|
case TypeSrcEnum.videogame: return TypeSrcEnumDTO.videogame;
|
|
default: return TypeSrcEnumDTO.movie;
|
|
}
|
|
}
|
|
|
|
// --------------------------- ToEntity --------------------------- \\
|
|
|
|
|
|
public static Character ToEntity(this CharacterDTO item)
|
|
{
|
|
Character character = new Character();
|
|
character.Id = item.Id;
|
|
character.Name = item.Name;
|
|
character.Images.ImgPath = item.imagePath ;
|
|
return character;
|
|
}
|
|
|
|
public static Commentary ToEntity(this CommentaryDTO item)
|
|
{
|
|
Commentary commentary = new Commentary();
|
|
commentary.Id = item.Id;
|
|
commentary.DateCommentary = item.Date;
|
|
commentary.Comment = item.Comment;
|
|
commentary.User.UserName = item.User;
|
|
commentary.User.Images.ImgPath = item.ImagePath;
|
|
return commentary;
|
|
}
|
|
|
|
// Surement a refaire car Faoirite Entity modifier sur branche EF
|
|
public static Favorite ToEntity(this FavoriteDTO item)
|
|
{
|
|
Favorite favorite = new Favorite();
|
|
favorite.IdUsers = item.IdUser;
|
|
favorite.IdQuote = item.IdQuote;
|
|
return favorite;
|
|
}
|
|
|
|
public static Images ToEntity(this ImageDTO item)
|
|
{
|
|
Images image = new Images();
|
|
image.Id = item.IdImage;
|
|
image.ImgPath = item.ImagePath;
|
|
return image;
|
|
}
|
|
|
|
public static Question ToEntity(this QuestionDTO item)
|
|
{
|
|
Question question = new Question();
|
|
question.Id = item.Id;
|
|
question.Text = item.Question;
|
|
question.AnswerA = item.AnswerA;
|
|
question.AnswerB = item.AnswerB;
|
|
question.AnswerC = item.AnswerC;
|
|
question.AnswerD = item.AnswerD;
|
|
question.CorrectAnswer = item.CorrectAnswer;
|
|
return question;
|
|
}
|
|
|
|
public static Quiz ToEntity(this QuizDTO item)
|
|
{
|
|
Quiz quiz = new Quiz();
|
|
quiz.Id = item.Id;
|
|
quiz.NbQuestion = item.NbQuestion;
|
|
quiz.Title = item.Title;
|
|
quiz.Images.ImgPath = item.ImagePath;
|
|
return quiz;
|
|
}
|
|
|
|
// Surement a refaire car QuizQuestion Entity modifier sur branche EF
|
|
public static QuizQuestion ToEntity(this QuizQuestionDTO item)
|
|
{
|
|
QuizQuestion quizQuestion = new QuizQuestion();
|
|
quizQuestion.IdQuiz = item.IdQuiz;
|
|
quizQuestion.IdQuestion = item.IdQuestion;
|
|
return quizQuestion;
|
|
}
|
|
|
|
public static Quote ToEntity(this QuoteDTO item)
|
|
{
|
|
Quote quote = new Quote();
|
|
quote.Id = item.Id;
|
|
quote.Content = item.Content;
|
|
quote.Source.Year = item.DateSource;
|
|
quote.Character.Name = item.Character;
|
|
quote.Source.Title = item.TitleSource;
|
|
quote.Langage = item.Langage.ToEntity();
|
|
quote.Character.Images.ImgPath = item.ImagePath;
|
|
quote.Likes = item.Like;
|
|
quote.Source.TypeSrc = item.Type.ToEntity();
|
|
return quote;
|
|
}
|
|
|
|
public static Source ToEntity(this SourceDTO item)
|
|
{
|
|
Source source = new Source();
|
|
source.Id = item.Id;
|
|
source.Year = item.Date;
|
|
source.Title = item.Title;
|
|
source.TypeSrc = item.Type.ToEntity();
|
|
return source;
|
|
}
|
|
|
|
public static Users ToEntity(this UserDTO item)
|
|
{
|
|
Users user = new Users();
|
|
user.Id = item.Id;
|
|
user.UserName = item.Pseudo;
|
|
user.Password = item.Password;
|
|
user.Email = item.Email;
|
|
user.Created = item.date;
|
|
user.Images.ImgPath = item.ImageProfil;
|
|
return user;
|
|
}
|
|
|
|
public static LangEnum ToEntity(this TypeLangageDTO item)
|
|
{
|
|
switch (item)
|
|
{
|
|
case TypeLangageDTO.vf: return LangEnum.vf;
|
|
case TypeLangageDTO.vo: return LangEnum.vo;
|
|
case TypeLangageDTO.ve: return LangEnum.ve;
|
|
default: return LangEnum.vo;
|
|
}
|
|
}
|
|
|
|
public static TypeSrcEnum ToEntity(this TypeSrcEnumDTO item)
|
|
{
|
|
switch (item)
|
|
{
|
|
case TypeSrcEnumDTO.movie: return TypeSrcEnum.movie;
|
|
case TypeSrcEnumDTO.book: return TypeSrcEnum.book;
|
|
case TypeSrcEnumDTO.serie: return TypeSrcEnum.series;
|
|
case TypeSrcEnumDTO.videogame: return TypeSrcEnum.videogame;
|
|
default: return TypeSrcEnum.movie;
|
|
}
|
|
}
|
|
}
|
|
}
|