上传实现Iservice接口
This commit is contained in:
@@ -18,5 +18,6 @@ namespace Yi.Framework.Interface
|
||||
/// <param name="_mould"></param>
|
||||
/// <returns></returns>
|
||||
Task<menu> GetMenuByMould(mould _mould);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
56
Yi.Framework/Yi.Framework.Service/MenuService.cs
Normal file
56
Yi.Framework/Yi.Framework.Service/MenuService.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public class MenuService:BaseService<menu>, IMenuService
|
||||
{
|
||||
public MenuService(DbContext Db) : base(Db) { }
|
||||
|
||||
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
|
||||
{
|
||||
var menuList = await GetEntitiesAsync(u=>_ids.Contains(u.id));
|
||||
menuList.ToList().ForEach(u => u.is_delete = (short)Common.Enum.DelFlagEnum.Deleted);
|
||||
return await UpdateListAsync(menuList);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<menu>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await GetEntitiesAsync(u => u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
public async Task<List<menu>> GetChildrenByMenu(menu _menu)
|
||||
{
|
||||
var menu_data = await GetEntity(u=>u.id==_menu.id);
|
||||
var childrenList = menu_data.children;
|
||||
return (List<menu>)childrenList;
|
||||
}
|
||||
|
||||
public async Task<menu> GetMenuMouldByMenu(menu _menu)
|
||||
{
|
||||
var menu_data = await GetEntity(u => u.id == _menu.id);
|
||||
return menu_data;
|
||||
}
|
||||
|
||||
public async Task<mould> GetMouldByMenu(menu _menu)
|
||||
{
|
||||
var menu_data = await GetEntity(u => u.id == _menu.id);
|
||||
var mould_data =await _Db.Set<mould>().Include(u => u.menu).Where(u => u.menu == menu_data).FirstOrDefaultAsync();
|
||||
return mould_data;
|
||||
}
|
||||
|
||||
public async Task<bool> SetMouldByMenu(int mouldId, int menuId)
|
||||
{
|
||||
var menu_data = await GetEntity(u => u.id == menuId);
|
||||
var mould_data = await _Db.Set<mould>().Where(u => u.id==mouldId).FirstOrDefaultAsync();
|
||||
menu_data.mould = mould_data;
|
||||
return await UpdateAsync(menu_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Yi.Framework/Yi.Framework.Service/MouldService.cs
Normal file
35
Yi.Framework/Yi.Framework.Service/MouldService.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public class MouldService:BaseService<mould>, IMouldService
|
||||
{
|
||||
public MouldService(DbContext Db) : base(Db) { }
|
||||
|
||||
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
|
||||
{
|
||||
var mouldList =await GetEntitiesAsync(u => _ids.Contains(u.id));
|
||||
mouldList.ToList().ForEach(u => u.is_delete = (short)Common.Enum.DelFlagEnum.Deleted);
|
||||
return await UpdateListAsync(mouldList);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<mould>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await GetEntitiesAsync(u => u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
public async Task<menu> GetMenuByMould(mould _mould)
|
||||
{
|
||||
var mould_data =await GetEntity(u => u.id ==_mould.id);
|
||||
return await _Db.Set<menu>().Where(u => u.mould == mould_data).FirstOrDefaultAsync();
|
||||
//return mould_data.menu;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,31 @@ namespace Yi.Framework.Service
|
||||
}
|
||||
public async Task<IEnumerable<role>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await _Db.Set<role>().Where(u => u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync();
|
||||
return await GetEntitiesAsync(u => u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
public async Task<List<menu>> GetMenusByRole(role _role)
|
||||
{
|
||||
return await _Db.Set<menu>().Include(u=>u.mould).ThenInclude(u=>u.menu)
|
||||
.Where(u=>u.roles.Contains(_role)&& u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<user>> GetUsersByRole(role _role)
|
||||
{
|
||||
return await _Db.Set<user>().Where(u => u.roles.Contains(_role) && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> SetMenusByRolesId(List<int> menuIds, int roleId)
|
||||
{
|
||||
var role_data = await GetEntity(u => u.id == roleId && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
if (role_data == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var menuList = _Db.Set<menu>().Where(u => menuIds.Contains(u.id)&&u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync();
|
||||
|
||||
role_data.menus = (ICollection<menu>)menuList;
|
||||
return await AddAsync(role_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,14 +6,15 @@ using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public class UserService: BaseService<user>,IUserService
|
||||
{
|
||||
public UserService(DbContext Db):base(Db)
|
||||
{
|
||||
public UserService(DbContext Db) :base(Db)
|
||||
{
|
||||
}
|
||||
public async Task<bool> DelListByUpdateAsync(List<int> _ids)
|
||||
{
|
||||
@@ -24,7 +25,59 @@ namespace Yi.Framework.Service
|
||||
|
||||
public async Task<IEnumerable<user>> GetAllEntitiesTrueAsync()
|
||||
{
|
||||
return await _Db.Set<user>().Where(u=>u.is_delete==(short)Common.Enum.DelFlagEnum.Normal).ToListAsync();
|
||||
return await GetEntitiesAsync(u => u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
}
|
||||
|
||||
public async Task<List<menu>> GetMenusByUser(user _user)
|
||||
{
|
||||
return await _Db.Set<menu>().Include(u => u.roles).ThenInclude(u => u.menus)
|
||||
.Where(u=>u.id==_user.id&& u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<mould>> GetMouldByUser(user _user)
|
||||
{
|
||||
return await _Db.Set<mould>().Include(u => u.menu)
|
||||
.Where(u => u.id == _user.id && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<role>> GetRolesByUser(user _user)
|
||||
{
|
||||
return await _Db.Set<role>().Include(u => u.users)
|
||||
.Where(u => u.id == _user.id && u.is_delete == (short)Common.Enum.DelFlagEnum.Normal).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> Login(user _user)
|
||||
{
|
||||
var user_data =await GetEntity(u => u.username == _user.username&&u.password==_user.password&&
|
||||
u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
if (user_data == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public async Task<bool> Register(user _user)
|
||||
{
|
||||
var user_data =await GetEntity(u => u.username == _user.username);
|
||||
if (user_data != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return await AddAsync(_user);
|
||||
}
|
||||
|
||||
public async Task<bool> SetRolesByUserId(List<int> roleIds, int userId)
|
||||
{
|
||||
var user_data =await GetEntity(u => u.id ==userId &&u.is_delete == (short)Common.Enum.DelFlagEnum.Normal);
|
||||
if (user_data == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var roleList = _Db.Set<role>().Where(u => roleIds.Contains(u.id)).ToList();
|
||||
user_data.roles = roleList;
|
||||
return await AddAsync(user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user