PageFunctionPermissionRepository.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.System;
  4. using OASystem.Domain.Entities.Resource;
  5. namespace OASystem.Infrastructure.Repositories.System
  6. {
  7. public class PageFunctionPermissionRepository : BaseRepository<Sys_PageFunctionPermission, PageFunctionPermissionView>
  8. {
  9. private readonly IMapper _mapper;
  10. public PageFunctionPermissionRepository(SqlSugarClient sqlSugar,IMapper mapper) : base(sqlSugar)
  11. {
  12. _mapper=mapper;
  13. }
  14. public async Task<Result> OperationFunInit(OperationFunInitDta dto)
  15. {
  16. Result result = new Result() { Code = -2, Msg = "未知错误" };
  17. try
  18. {
  19. if (dto.Status == 1)//添加
  20. {
  21. string selectSql = string.Format(@"select * from Sys_PageFunctionPermission where FunctionName='{0}' and IsDel='{1}'"
  22. , dto.FunctionName, 0);
  23. var FunInit = await _sqlSugar.SqlQueryable<Sys_PageFunctionPermission>(selectSql).FirstAsync();//查询是否存在
  24. if (FunInit != null)
  25. {
  26. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  27. }
  28. else//不存在,可添加
  29. {
  30. Sys_PageFunctionPermission Function = _mapper.Map<Sys_PageFunctionPermission>(dto);
  31. int id = await AddAsyncReturnId(Function);
  32. if (id == 0)
  33. {
  34. return result = new Result() { Code = -1, Msg = "添加失败!" };
  35. }
  36. result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  37. }
  38. }
  39. else if (dto.Status == 2)//修改
  40. {
  41. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Sys_PageFunctionPermission
  42. {
  43. FunctionName=dto.FunctionName,
  44. FunctionCode=dto.FunctionCode,
  45. IsEnable=dto.IsEnable,
  46. Remark = dto.Remark,
  47. });
  48. if (!res)
  49. {
  50. return result = new Result() { Code = -1, Msg = "修改失败!" };
  51. }
  52. result = new Result() { Code = 0, Msg = "修改成功!" };
  53. }
  54. else
  55. {
  56. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  57. }
  58. }
  59. catch (Exception ex)
  60. {
  61. return result = new Result() { Code = -2, Msg = "程序错误!" };
  62. }
  63. return result;
  64. }
  65. }
  66. }