mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-11-08 10:24:44 +08:00
优化AutoMapper代码
This commit is contained in:
@@ -14,14 +14,17 @@ namespace OpenAuth.App
|
||||
private IUserRepository _repository;
|
||||
private IModuleRepository _moduleRepository;
|
||||
private IRelevanceRepository _relevanceRepository;
|
||||
private IRepository<ModuleElement> _moduleElementRepository;
|
||||
|
||||
public LoginApp(IUserRepository repository,
|
||||
IModuleRepository moduleRepository,
|
||||
IRelevanceRepository relevanceRepository)
|
||||
IRelevanceRepository relevanceRepository,
|
||||
IRepository<ModuleElement> moduleElementRepository )
|
||||
{
|
||||
_repository = repository;
|
||||
_moduleRepository = moduleRepository;
|
||||
_relevanceRepository = relevanceRepository;
|
||||
_moduleElementRepository = moduleElementRepository;
|
||||
}
|
||||
|
||||
public LoginUserVM Login(string userName, string password)
|
||||
@@ -48,7 +51,7 @@ namespace OpenAuth.App
|
||||
(u.FirstId == user.Id && u.Key == "UserModule") ||
|
||||
(u.Key == "RoleModule" && userRoleIds.Contains(u.FirstId))).Select(u =>u.SecondId).ToList();
|
||||
//<2F>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ӵ<EFBFBD>е<EFBFBD>ģ<EFBFBD><C4A3>
|
||||
loginVM.Modules = _moduleRepository.Find(u => moduleIds.Contains(u.Id)).ToList();
|
||||
loginVM.Modules = _moduleRepository.Find(u => moduleIds.Contains(u.Id)).MapToList<ModuleView>();
|
||||
|
||||
return loginVM;
|
||||
}
|
||||
@@ -65,7 +68,7 @@ namespace OpenAuth.App
|
||||
Name = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD>"
|
||||
}
|
||||
};
|
||||
loginUser.Modules = _moduleRepository.Find(null).ToList();
|
||||
loginUser.Modules = _moduleRepository.Find(null).MapToList<ModuleView>();
|
||||
return loginUser;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,32 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.App
|
||||
// Author : Yubao Li
|
||||
// Created : 12-01-2015
|
||||
//
|
||||
// Last Modified By : Yubao Li
|
||||
// Last Modified On : 12-01-2015
|
||||
// ***********************************************************************
|
||||
// <copyright file="LoginUserVM.cs" company="">
|
||||
// Copyright (c) . All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>登陆视图模型</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenAuth.Domain;
|
||||
|
||||
namespace OpenAuth.App.ViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 登陆用户视图模型
|
||||
/// </summary>
|
||||
public class LoginUserVM
|
||||
{
|
||||
public User User { get; set; }
|
||||
/// <summary>
|
||||
/// 用户可以访问到的模块(包括所属角色与自己的所有模块)
|
||||
/// </summary>
|
||||
public List<Module> Modules { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户可以访问到的模块中的元素
|
||||
/// </summary>
|
||||
public List<ModuleElement> ModuleElements { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.App
|
||||
// Author : Yubao Li
|
||||
// Created : 12-01-2015
|
||||
//
|
||||
// Last Modified By : Yubao Li
|
||||
// Last Modified On : 12-01-2015
|
||||
// ***********************************************************************
|
||||
// <copyright file="LoginUserVM.cs" company="">
|
||||
// Copyright (c) . All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>登陆视图模型</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenAuth.Domain;
|
||||
|
||||
namespace OpenAuth.App.ViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 登陆用户视图模型
|
||||
/// </summary>
|
||||
public class LoginUserVM
|
||||
{
|
||||
public User User { get; set; }
|
||||
/// <summary>
|
||||
/// 用户可以访问到的模块(包括所属角色与自己的所有模块)
|
||||
/// </summary>
|
||||
public List<ModuleView> Modules { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Infrastructure;
|
||||
using Infrastructure;
|
||||
using OpenAuth.Domain;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenAuth.App.ViewModel
|
||||
{
|
||||
@@ -39,17 +39,21 @@ namespace OpenAuth.App.ViewModel
|
||||
/// <summary>
|
||||
/// 子节点
|
||||
/// </summary>
|
||||
public List<ModuleView> Childern = new List<ModuleView>();
|
||||
public List<ModuleView> Childern = new List<ModuleView>();
|
||||
|
||||
/// <summary>
|
||||
/// 模块中的元素
|
||||
/// </summary>
|
||||
public List<ModuleElement> Elements = new List<ModuleElement>();
|
||||
|
||||
public static implicit operator ModuleView(Module module)
|
||||
{
|
||||
return AutoMapperExt.ConvertTo<Module, ModuleView>(module);
|
||||
return module.MapTo<ModuleView>();
|
||||
}
|
||||
|
||||
public static implicit operator Module(ModuleView view)
|
||||
{
|
||||
return AutoMapperExt.ConvertTo<ModuleView, Module>(view);
|
||||
return view.MapTo<Module>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,12 +52,12 @@ namespace OpenAuth.App.ViewModel
|
||||
|
||||
public static implicit operator RoleVM(Role role)
|
||||
{
|
||||
return AutoMapperExt.ConvertTo<Role,RoleVM>(role);
|
||||
return role.MapTo<RoleVM>();
|
||||
}
|
||||
|
||||
public static implicit operator Role(RoleVM rolevm)
|
||||
{
|
||||
return AutoMapperExt.ConvertTo<RoleVM, Role>(rolevm);
|
||||
return rolevm.MapTo<Role>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -71,12 +71,12 @@ namespace OpenAuth.App.ViewModel
|
||||
|
||||
public static implicit operator UserView(User user)
|
||||
{
|
||||
return AutoMapperExt.ConvertTo<User, UserView>(user);
|
||||
return user.MapTo<UserView>();
|
||||
}
|
||||
|
||||
public static implicit operator User(UserView view)
|
||||
{
|
||||
return AutoMapperExt.ConvertTo<UserView, User>(view);
|
||||
return view.MapTo<User>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user