
Some checks failed
TechAct / explore-gitea-actions (push) Failing after 13s
- 重构AppMainStruct、AssignmentQuestion、Question等实体模型 - 更新相关DTO以匹配新的数据结构 - 优化前端页面布局和组件 - 添加全局信息和笔记功能相关代码 - 更新数据库迁移和程序配置
71 lines
2.0 KiB
C#
71 lines
2.0 KiB
C#
using AutoMapper;
|
|
using AutoMapper.Internal.Mappers;
|
|
using Entities.Contracts;
|
|
using Entities.DTO;
|
|
using Newtonsoft.Json;
|
|
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace TechHelper.Context
|
|
{
|
|
public class AutoMapperProFile : Profile
|
|
{
|
|
|
|
public static class EnumMappingHelpers
|
|
{
|
|
public static TEnum ParseEnumSafe<TEnum>(string sourceString, TEnum defaultValue) where TEnum : struct, Enum
|
|
{
|
|
if (Enum.TryParse(sourceString, true, out TEnum parsedValue))
|
|
{
|
|
return parsedValue;
|
|
}
|
|
return defaultValue;
|
|
}
|
|
}
|
|
|
|
public AutoMapperProFile()
|
|
{
|
|
CreateMap<UserForRegistrationDto, User>()
|
|
.ForMember(dest => dest.Id, opt => opt.Ignore())
|
|
.ForMember(dest => dest.UserName, opt => opt.MapFrom(src => src.Name))
|
|
.ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.Email))
|
|
.ForMember(dest => dest.PhoneNumber, opt => opt.MapFrom(src => src.PhoneNumber))
|
|
.ForMember(dest => dest.Address, opt => opt.MapFrom(src => src.HomeAddress))
|
|
.ForMember(dest => dest.PasswordHash, opt => opt.Ignore())
|
|
.ForMember(dest => dest.EmailConfirmed, opt => opt.Ignore());
|
|
|
|
CreateMap<ClassDto, Class>()
|
|
.ForMember(d => d.Number, o => o.MapFrom(src => src.Class))
|
|
.ReverseMap();
|
|
|
|
|
|
|
|
// Assignment
|
|
CreateMap<AssignmentDto, Assignment>().ReverseMap();
|
|
|
|
CreateMap<AssignmentQuestionDto, AssignmentQuestion>().ReverseMap();
|
|
|
|
CreateMap<QuestionDto, Question>().ReverseMap();
|
|
|
|
CreateMap<QuestionContext, QuestionContextDto>().ReverseMap();
|
|
|
|
|
|
|
|
|
|
// Submission
|
|
CreateMap<SubmissionDto, Submission>().ReverseMap();
|
|
|
|
CreateMap<SubmissionDetailDto, SubmissionDetail>().ReverseMap();
|
|
|
|
|
|
CreateMap<SubjectTypeMetadataDto, Global>()
|
|
.ForMember(dest => dest.Info, opt => opt.MapFrom(src => JsonConvert.SerializeObject(src.Data)));
|
|
CreateMap<Global, SubjectTypeMetadataDto>()
|
|
.ForMember(dest => dest.Data, opt => opt.MapFrom(src => JsonConvert.DeserializeObject<Dictionary<string, (string Color, string DisplayName)>>(src.Info)));
|
|
|
|
}
|
|
}
|
|
|
|
}
|