112 lines
3.8 KiB
C#
112 lines
3.8 KiB
C#
|
|
using System.Collections.Generic;
|
|||
|
|
using AutoMapper;
|
|||
|
|
using OnlineAssessment.Domain.Models;
|
|||
|
|
using OnlineAssessment.Domain.ViewModels;
|
|||
|
|
|
|||
|
|
namespace OnlineAssessment.Data
|
|||
|
|
{
|
|||
|
|
public class AutoMapping : Profile
|
|||
|
|
{
|
|||
|
|
public AutoMapping()
|
|||
|
|
{
|
|||
|
|
CreateMap<Roles, Role>();
|
|||
|
|
CreateMap<Role, Roles>();
|
|||
|
|
|
|||
|
|
CreateMap<Languages, Language>();
|
|||
|
|
CreateMap<Language, Languages>();
|
|||
|
|
|
|||
|
|
CreateMap<Institutes, InstituteAddModel>();
|
|||
|
|
CreateMap<Institutes, InstituteViewModel>();
|
|||
|
|
CreateMap<InstituteViewModel, Institutes>();
|
|||
|
|
CreateMap<InstituteAddModel, Institutes>();
|
|||
|
|
|
|||
|
|
|
|||
|
|
CreateMap<SubCategories, SubCategory>();
|
|||
|
|
CreateMap<SubCategory, SubCategories>();
|
|||
|
|
|
|||
|
|
CreateMap<StudyNotes, StudyNote>();
|
|||
|
|
CreateMap<StudyNotes, StudyNoteViewAllModel>();
|
|||
|
|
CreateMap<StudyNote, StudyNotes>();
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
CreateMap<QuestionTypes, QuestionType>();
|
|||
|
|
CreateMap<QuestionType, QuestionTypes>();
|
|||
|
|
|
|||
|
|
CreateMap<ExamTypes, ExamType>();
|
|||
|
|
CreateMap<ExamType, ExamTypes>();
|
|||
|
|
|
|||
|
|
CreateMap<UserGroups, UserGroup>();
|
|||
|
|
CreateMap<UserGroup, UserGroups>();
|
|||
|
|
|
|||
|
|
//var config = new MapperConfiguration(cfg =>
|
|||
|
|
//{
|
|||
|
|
// cfg.CreateMap<Subscriptions, Subscription>().IncludeMembers(s => s.Plan);
|
|||
|
|
// cfg.CreateMap<Plans, Subscription>(MemberList.None);
|
|||
|
|
// cfg.CreateMap<Plan, Subscription>(MemberList.None);
|
|||
|
|
|
|||
|
|
//});
|
|||
|
|
//config.AssertConfigurationIsValid();
|
|||
|
|
|
|||
|
|
|
|||
|
|
//CreateMap<Users, User>(); // to map from User to UserViewModel
|
|||
|
|
|
|||
|
|
//https://docs.automapper.org/en/stable/Flattening.html
|
|||
|
|
//var config = new MapperConfiguration(cfg =>
|
|||
|
|
//{
|
|||
|
|
// cfg.CreateMap<Source, Destination>().IncludeMembers(s => s.InnerSource, s => s.OtherInnerSource);
|
|||
|
|
// cfg.CreateMap<InnerSource, Destination>(MemberList.None);
|
|||
|
|
// cfg.CreateMap<OtherInnerSource, Destination>(MemberList.None);
|
|||
|
|
|
|||
|
|
// cfg.CreateMap<Users, UserViewModel>().IncludeMembers(s => s.Role, s => s.Institute);
|
|||
|
|
// cfg.CreateMap<Roles, UserViewModel>(MemberList.None);
|
|||
|
|
// cfg.CreateMap<Institutes, UserViewModel>(MemberList.None);
|
|||
|
|
//});
|
|||
|
|
//config.AssertConfigurationIsValid();
|
|||
|
|
|
|||
|
|
//var source = new Source
|
|||
|
|
//{
|
|||
|
|
// Name = "name",
|
|||
|
|
// InnerSource = new InnerSource { Description = "description" },
|
|||
|
|
// OtherInnerSource = new OtherInnerSource { Title = "title" }
|
|||
|
|
//};
|
|||
|
|
//var destination = mapper.Map<Destination>(source);
|
|||
|
|
//destination.Name.ShouldBe("name");
|
|||
|
|
//destination.Description.ShouldBe("description");
|
|||
|
|
//destination.Title.ShouldBe("title");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static class AutoMapperExtensions
|
|||
|
|
{
|
|||
|
|
public static List<TDestination> MapList<TSource, TDestination>(this IMapper mapper, List<TSource> source)
|
|||
|
|
{
|
|||
|
|
return mapper.Map<List<TDestination>>(source);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//class Source
|
|||
|
|
//{
|
|||
|
|
// public string Name { get; set; }
|
|||
|
|
// public InnerSource InnerSource { get; set; }
|
|||
|
|
// public OtherInnerSource OtherInnerSource { get; set; }
|
|||
|
|
//}
|
|||
|
|
//class InnerSource
|
|||
|
|
//{
|
|||
|
|
// public string Name { get; set; }
|
|||
|
|
// public string Description { get; set; }
|
|||
|
|
//}
|
|||
|
|
//class OtherInnerSource
|
|||
|
|
//{
|
|||
|
|
// public string Name { get; set; }
|
|||
|
|
// public string Description { get; set; }
|
|||
|
|
// public string Title { get; set; }
|
|||
|
|
//}
|
|||
|
|
//class Destination
|
|||
|
|
//{
|
|||
|
|
// public string Name { get; set; }
|
|||
|
|
// public string Description { get; set; }
|
|||
|
|
// public string Title { get; set; }
|
|||
|
|
//}
|
|||
|
|
}
|