using Central.Control.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MES.Production.Service.ServiceImp
{
///
/// Service层用户与角色关系接口
/// add 作者: 季健国 QQ:181589805 by 2016-05-22
///
public class UserRoleManage : RepositoryBase,IService.IUserRoleManage
{
///
/// 设置用户角色
/// add 作者: 季健国 QQ:181589805 by 2016-06-10
///
/// 用户ID
/// 角色ID字符串
public bool SetUserRole(int userId, string roleId)
{
try
{
//1、删除用户角色
this.Delete(p => p.FK_USERID == userId);
//2、设置当前用户的角色
if (string.IsNullOrEmpty(roleId)) return true;
foreach (var entity in roleId.Split(',').Select(t => new SYS_USER_ROLE()
{
FK_USERID = userId,
FK_ROLEID = int.Parse(t)
}))
{
this.dbSet.Add(entity);
}
return this.Context.SaveChanges() > 0;
}
catch (Exception e) { throw e; }
}
}
}