添加automapper
This commit is contained in:
@@ -16,6 +16,7 @@ using Yi.Framework.DTOModel;
|
|||||||
using Yi.Framework.Interface;
|
using Yi.Framework.Interface;
|
||||||
using Yi.Framework.Model.Models;
|
using Yi.Framework.Model.Models;
|
||||||
using Yi.Framework.WebCore;
|
using Yi.Framework.WebCore;
|
||||||
|
using Yi.Framework.WebCore.Mapper;
|
||||||
|
|
||||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||||
{
|
{
|
||||||
@@ -46,11 +47,12 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 登录方法,要返回data:{user,token} token
|
/// 登录方法,要返回data:{user,token} token
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="_user"></param>
|
/// <param name="login"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<Result> Login(user _user)
|
public async Task<Result> Login(loginDto login)
|
||||||
{
|
{
|
||||||
|
var _user= MapperHelper.Map<user, loginDto>(login);
|
||||||
var user_data = await _userService.Login(_user);
|
var user_data = await _userService.Login(_user);
|
||||||
if (user_data == null)
|
if (user_data == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
<name>Yi.Framework.ApiMicroservice</name>
|
<name>Yi.Framework.ApiMicroservice</name>
|
||||||
</assembly>
|
</assembly>
|
||||||
<members>
|
<members>
|
||||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Login(Yi.Framework.Model.Models.user)">
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Login(Yi.Framework.DTOModel.loginDto)">
|
||||||
<summary>
|
<summary>
|
||||||
登录方法,要返回data:{user,token} token
|
登录方法,要返回data:{user,token} token
|
||||||
</summary>
|
</summary>
|
||||||
<param name="_user"></param>
|
<param name="login"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Logout">
|
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AccountController.Logout">
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
14
Yi.Framework.Net6/Yi.Framework.DTOModel/loginDto.cs
Normal file
14
Yi.Framework.Net6/Yi.Framework.DTOModel/loginDto.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Yi.Framework.DTOModel
|
||||||
|
{
|
||||||
|
public class loginDto
|
||||||
|
{
|
||||||
|
public string username { get; set; }
|
||||||
|
public string password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using AutoMapper.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Yi.Framework.WebCore.Mapper
|
||||||
|
{
|
||||||
|
public class MapperHelper
|
||||||
|
{
|
||||||
|
public static IMapper Profile()
|
||||||
|
{
|
||||||
|
var cfg = new MapperConfigurationExpression();
|
||||||
|
cfg.AddProfile<AutoMapperProfile>();
|
||||||
|
cfg.AddProfile<RegisterMapProfile>();
|
||||||
|
var config = new MapperConfiguration(cfg);
|
||||||
|
IMapper mapper = new AutoMapper.Mapper(config);
|
||||||
|
return mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Target Map<Target, Source>(Source source)
|
||||||
|
{
|
||||||
|
var cfg = new MapperConfigurationExpression();
|
||||||
|
cfg.CreateMap<Source, Target>();
|
||||||
|
var config = new MapperConfiguration(cfg);
|
||||||
|
IMapper mapper = new AutoMapper.Mapper(config);
|
||||||
|
return mapper.Map<Source, Target>(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Yi.Framework.WebCore.Mapper
|
||||||
|
{
|
||||||
|
public class AutoMapperProfile : Profile
|
||||||
|
{
|
||||||
|
// 添加你的实体映射关系.
|
||||||
|
public AutoMapperProfile()
|
||||||
|
{
|
||||||
|
//CreateMap<DBPoundSheet, PoundSheetViewModel>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Yi.Framework.WebCore.Mapper
|
||||||
|
{
|
||||||
|
public class RegisterMapProfile : Profile
|
||||||
|
{
|
||||||
|
//添加你的实体映射关系和出参字段
|
||||||
|
//public RegisterMapProfile()
|
||||||
|
//{
|
||||||
|
// #region 排班信息
|
||||||
|
// CreateMap<JToken, SchedulHeadViewModel>()
|
||||||
|
// .ForMember(dest => dest.HospitalId,
|
||||||
|
// options => options.MapFrom(c => c.SelectToken("Hospital_ID")))
|
||||||
|
// .ForMember(dest => dest.BranchId,
|
||||||
|
// options => options.MapFrom(c => c.SelectToken("Branch_ID")))
|
||||||
|
// .ForMember(dest => dest.SchedulId,
|
||||||
|
// options => options.MapFrom(c => c.SelectToken("ScheduHeadID")));
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Yi.Framework.WebCore.MiddlewareExtend
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 通用autoMapper扩展
|
||||||
|
/// </summary>
|
||||||
|
public static class AutoMapperExtension
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddAutoMapperExtensionService(this IServiceCollection services,Type type)
|
||||||
|
{
|
||||||
|
services.AddAutoMapper(type);
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
<PackageReference Include="Autofac" Version="6.3.0" />
|
<PackageReference Include="Autofac" Version="6.3.0" />
|
||||||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0" />
|
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0" />
|
||||||
<PackageReference Include="Autofac.Extras.DynamicProxy" Version="6.0.0" />
|
<PackageReference Include="Autofac.Extras.DynamicProxy" Version="6.0.0" />
|
||||||
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
|
||||||
<PackageReference Include="Com.Ctrip.Framework.Apollo.Configuration" Version="2.5.0" />
|
<PackageReference Include="Com.Ctrip.Framework.Apollo.Configuration" Version="2.5.0" />
|
||||||
<PackageReference Include="DotNetCore.CAP" Version="5.2.0" />
|
<PackageReference Include="DotNetCore.CAP" Version="5.2.0" />
|
||||||
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="5.2.0" />
|
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="5.2.0" />
|
||||||
|
|||||||
Reference in New Issue
Block a user