public AjaxMessage EmployeePowerCreate(int employeeId, string channel) { AjaxMessage ajax = new AjaxMessage(); ajax.IsSuccess = false; try { //逗号隔开获取菜单ID string[] power = channel.Split(','); Sys_Employee employee = _empService.GetByID(employeeId); List <Sys_EmployeePower> powerList = _empPowerService.GetAllByEmployeeId(employeeId); foreach (var item in powerList) { item.Status = (byte)SysStatus.Disable; _empPowerService.Update(item); } int result = 0; for (int i = 0; i < power.Length; i++) { int ChannelId = power[i].ToInt32(); bool IsExists = _empPowerService.CheckPower(employeeId, ChannelId); Sys_Channel m_channel = _channelService.GetByID(ChannelId); Sys_EmployeePower m_empPower = null; if (IsExists == false) //不存在 就添加 { m_empPower = new Sys_EmployeePower(); m_empPower.Powername = m_channel.ChannelName; m_empPower.EmployeeID = employeeId; m_empPower.DepartmentID = employee.DepartmentID; m_empPower.ChannelID = ChannelId; m_empPower.UrlAddress = m_channel.ChannelAddress; m_empPower.CreateDate = DateTime.Now; m_empPower.Status = (byte)SysStatus.Enable; m_empPower.Parent = m_channel.Parent; m_empPower.Sort = m_channel.SortInt; //区别 1级菜单和2级菜单 if (m_channel.Parent == 0) { m_empPower.ItemLevel = 1; } else { m_empPower.ItemLevel = 2; } result = _empPowerService.Insert(m_empPower); } else { m_empPower = _empPowerService.GetEmpPower(employeeId, ChannelId); m_empPower.Powername = m_channel.ChannelName; m_empPower.UrlAddress = m_channel.ChannelAddress; m_empPower.Status = (byte)SysStatus.Enable; m_empPower.Parent = m_channel.Parent; m_empPower.Sort = m_channel.SortInt; result = _empPowerService.Update(m_empPower); } } if (result > 0) { ajax.IsSuccess = true; ajax.Message = "保存权限成功"; } } catch (Exception e) { ajax.Message = e.Message; } return(ajax); }
public AjaxMessage CreateLoadEmp() { AjaxMessage ajax = new AjaxMessage(); ajax.IsSuccess = false; ajax.Message = ""; try { bool isExists = _empService.CheckLoginName("wupeng"); if (isExists == false) { Sys_Employee emp = new Sys_Employee(); emp.JobID = -1; emp.DepartmentID = -1; emp.EmployeeTypeID = -1; emp.EmployeeName = "吴鹏"; emp.LoginName = "wupeng"; emp.PassWord = "******"; emp.CreateDate = DateTime.Now; emp.ComeInDate = DateTime.Now; emp.Sex = false; emp.BornDate = DateTime.Now.AddYears(-10); emp.TelPhone = ""; emp.Status = (byte)SysStatus.Enable; //建立帐号 int final = _empService.Insert(emp); if (final > 0) { //给予权限 string channel = "1,2,3,4,5,6"; //逗号隔开获取菜单ID string[] power = channel.Split(','); int result = 0; for (int i = 0; i < power.Length; i++) { int ChannelId = power[i].ToInt32(); Sys_Channel m_channel = _channelService.GetByID(ChannelId); Sys_EmployeePower m_empPower = null; m_empPower = new Sys_EmployeePower(); m_empPower.Powername = m_channel.ChannelName; m_empPower.EmployeeID = emp.EmployeeID; m_empPower.DepartmentID = emp.DepartmentID; m_empPower.ChannelID = ChannelId; m_empPower.UrlAddress = m_channel.ChannelAddress; m_empPower.CreateDate = DateTime.Now; m_empPower.Status = (byte)SysStatus.Enable; m_empPower.Parent = m_channel.Parent; m_empPower.Sort = m_channel.SortInt; //区别 1级菜单和2级菜单 if (m_channel.Parent == 0) { m_empPower.ItemLevel = 1; } else { m_empPower.ItemLevel = 2; } //添加到数据库 result = _empPowerService.Insert(m_empPower); if (result > 0) { ajax.IsSuccess = true; ajax.Message = "建立初始账户成功"; } } } } } catch (Exception e) { ajax.Message = e.Message; } return(ajax); }