57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using RIZO.Server.IService;
|
|
using RIZO.Server.IConfiguration;
|
|
using RIZO.Server.IEFContext;
|
|
using RIZO.Server.Models;
|
|
|
|
namespace RIZO.Server.Service
|
|
{
|
|
public class UserService : ServiceBase, IUserService
|
|
{
|
|
IUtils _utils;
|
|
public UserService(RIZO.Server.IEFContext.IEFContext eFContext, IUtils utils) : base(eFContext)
|
|
{
|
|
_utils = utils;
|
|
}
|
|
|
|
public List<RoleInfo> GetRolesByUserId(int userId)
|
|
{
|
|
var roles = (from ur in Context.Set<UserRole>()
|
|
where ur.UserId == userId
|
|
select ur.RoleId).ToList();
|
|
|
|
return (from role in Context.Set<RoleInfo>()
|
|
where roles.Contains(role.RoleId)
|
|
select role).ToList();
|
|
}
|
|
|
|
public void ResetPassword(int userId)
|
|
{
|
|
Context.Set<SysUserInfo>().Where(u => u.UserId == userId).ToList().ForEach(u => u.Password = _utils.GetMD5Str(_utils.GetMD5Str("123456") + "|" + u.UserName));
|
|
Context.SaveChanges();
|
|
}
|
|
|
|
public void SaveUser(string data)
|
|
{
|
|
// 反序列化:用户信息实例
|
|
var value = Newtonsoft.Json.JsonConvert.DeserializeObject<SysUserInfo>(data);
|
|
|
|
//value.state = 1;
|
|
|
|
// 当新增的时候
|
|
if (value.UserId == 0)
|
|
{
|
|
value.UserIcon = "image/show/temp.jpg";
|
|
value.Password = _utils.GetMD5Str(_utils.GetMD5Str("123456") + "|" + value.UserName);
|
|
}
|
|
|
|
Context.Entry(value).State = value.UserId == 0 ?
|
|
EntityState.Added :
|
|
EntityState.Modified;
|
|
Context.SaveChanges();
|
|
}
|
|
}
|
|
}
|