using System; using System.Collections.Generic; using System.IRepositories; using System.Linq; using System.Model; using System.Security.Claims; using System.Threading.Tasks; using System.Web; using System.Common; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using TVShoppingCallCenter_ZLJ.Models.Dtos; namespace TVShoppingCallCenter_ZLJ.Controllers.System { [Authorize] [Produces("application/json")] [Route("api/[controller]")] public class ModuleButtonInfoController : BaseController { private readonly ISys_ModuleButtonInfoRepository _sys_modulebuttoninfoRepository; public ModuleButtonInfoController(ISys_ModuleButtonInfoRepository sys_modulebuttoninfoRepository) { _sys_modulebuttoninfoRepository = sys_modulebuttoninfoRepository; } [HttpGet("getlist")] public async Task GetListAsync(int menuid = 0) { var list_ModuleInfoButton = await _sys_modulebuttoninfoRepository.GetListALL(b => b.F_State == (int)EnumDelState.Enabled && b.F_MenuId == menuid, o => o.F_Sort, SqlSugar.OrderByType.Asc); List list_ModuleInfoButtonDto = new List(); foreach (var entity in list_ModuleInfoButton) { ModuleInfoButtonDto _dto = new ModuleInfoButtonDto { id = entity.F_Id, moduleid = entity.F_MenuId.Value, name = entity.F_ButtonName, jsevent = entity.F_JSEvent, icon = entity.F_Icon, url = entity.F_UrlAddress, flag = entity.F_State.Value, remark = entity.F_Remark, sort = entity.F_Sort.Value }; list_ModuleInfoButtonDto.Add(_dto); } return Success("获取按钮", list_ModuleInfoButton); } /// /// 获取菜单按钮实体 /// /// /// [HttpGet("getmodule")] public async Task GetModuleAsync(int mid = 0) { var entity = (await _sys_modulebuttoninfoRepository.GetSingle(x => x.F_Id == mid)); if (entity != null) { ModuleInfoButtonDto _dto = new ModuleInfoButtonDto { id = entity.F_Id, moduleid = entity.F_MenuId.Value, name = entity.F_ButtonName, jsevent = entity.F_JSEvent, code = entity.F_ButtonCode, icon = entity.F_Icon, url = entity.F_UrlAddress, flag = entity.F_State.Value, remark = entity.F_Remark, sort = entity.F_Sort.Value }; return Success("加载按钮成功", _dto); } else { return Error("加载按钮失败"); } } /// /// 添加按钮 /// /// /// [HttpPost("addmodule")] public async Task AddModule(ModuleInfoButtonDto input) { if (input.moduleid>0) return Error("参数错误"); if (string.IsNullOrEmpty(input.name)) return Error("请输入按钮名称"); if (string.IsNullOrEmpty(input.code)) return Error("请输入按钮代码"); var entity_ModuleInfoButton = new T_Sys_ModuleButtonInfo(); entity_ModuleInfoButton.F_MenuId = input.moduleid; entity_ModuleInfoButton.F_ButtonCode = input.code; entity_ModuleInfoButton.F_ButtonName = input.name; entity_ModuleInfoButton.F_JSEvent = input.jsevent; entity_ModuleInfoButton.F_Icon = input.icon; entity_ModuleInfoButton.F_UrlAddress = HttpUtility.UrlDecode(input.url); entity_ModuleInfoButton.F_State = Convert.ToInt32(input.flag); entity_ModuleInfoButton.F_Remark = input.remark; entity_ModuleInfoButton.F_Sort = input.sort; entity_ModuleInfoButton.F_CreateOn = DateTime.Now.ToLocalTime(); entity_ModuleInfoButton.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value; var res = await _sys_modulebuttoninfoRepository.Add(entity_ModuleInfoButton); if (res>0) { return Success("按钮添加成功"); } else { return Error("菜单按钮添加失败,请重试!"); } } /// /// 更新按钮 /// /// /// [HttpPost("updatemodule")] public async Task UpdateModule(ModuleInfoButtonDto input) { if (input.moduleid > 0) return Error("参数错误"); if (string.IsNullOrEmpty(input.name)) return Error("请输入按钮名称"); if (string.IsNullOrEmpty(input.code)) return Error("请输入按钮代码"); var entity_ModuleInfoButton = new T_Sys_ModuleButtonInfo(); entity_ModuleInfoButton.F_Id = input.id; entity_ModuleInfoButton.F_MenuId = input.moduleid; entity_ModuleInfoButton.F_ButtonCode = input.code; entity_ModuleInfoButton.F_ButtonName = input.name; entity_ModuleInfoButton.F_JSEvent = input.jsevent; entity_ModuleInfoButton.F_Icon = input.icon; entity_ModuleInfoButton.F_UrlAddress = HttpUtility.UrlDecode(input.url); entity_ModuleInfoButton.F_State = Convert.ToInt32(input.flag); entity_ModuleInfoButton.F_Remark = input.remark; entity_ModuleInfoButton.F_Sort = input.sort; entity_ModuleInfoButton.F_LastModifyOn = DateTime.Now.ToLocalTime(); entity_ModuleInfoButton.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value; if (await _sys_modulebuttoninfoRepository.Update(entity_ModuleInfoButton)) { return Success("按钮修改成功"); } else { return Error("按钮修改失败,请重试!"); } } /// /// 删除菜单按钮 /// /// /// [HttpPost("delmodule")] public async Task DelModuleAsync(int[] ids) { var res = 0; if (ids != null && ids.Length > 0) { foreach (var item in ids) { var ml = await _sys_modulebuttoninfoRepository.GetSingle(x => x.F_Id == item); ml.F_State = (int)EnumDelState.Delete; ml.F_DeleteOn = DateTime.Now.ToLocalTime(); ml.F_DeleteBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value; if (_sys_modulebuttoninfoRepository.Update(ml).Result) res += 1; } if (res == ids.Length) return Success("删除成功"); else if (res > 0 && res < ids.Length) return Error("部分删除失败,请查看后重新操作"); else return Error("删除失败,请查看后重新操作"); } else { return Error("请选择要删除的记录"); } } /// /// 编辑菜单按钮 /// /// /// [HttpPost("editmodule")] public async Task EditModuleAsync(ModuleInfoButtonDto input) { if (input.moduleid > 0) return Error("参数错误"); if (string.IsNullOrEmpty(input.name)) return Error("请输入按钮名称"); if (string.IsNullOrEmpty(input.code)) return Error("请输入按钮代码"); var entity_ModuleInfoButton = await _sys_modulebuttoninfoRepository.GetSingle(x=>x.F_Id==input.id); if (entity_ModuleInfoButton != null) { entity_ModuleInfoButton.F_MenuId = input.moduleid; entity_ModuleInfoButton.F_ButtonCode = input.code; entity_ModuleInfoButton.F_ButtonName = input.name; entity_ModuleInfoButton.F_JSEvent = input.jsevent; entity_ModuleInfoButton.F_Icon = input.icon; entity_ModuleInfoButton.F_UrlAddress = HttpUtility.UrlDecode(input.url); entity_ModuleInfoButton.F_State = Convert.ToInt32(input.flag); entity_ModuleInfoButton.F_Remark = input.remark; entity_ModuleInfoButton.F_Sort = input.sort; entity_ModuleInfoButton.F_LastModifyOn = DateTime.Now.ToLocalTime(); entity_ModuleInfoButton.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value; if (await _sys_modulebuttoninfoRepository.Update(entity_ModuleInfoButton)) { return Success("按钮修改成功"); } else { return Error("按钮修改失败,请重试!"); } } else { return Error("菜单对象获取失败"); } } } }