DelegationEnDataRepository.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Entities.Groups;
  5. using OASystem.Domain.Entities.Resource;
  6. using OASystem.Domain.ViewModels.Groups;
  7. using OASystem.Infrastructure.Repositories.System;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace OASystem.Infrastructure.Repositories.Groups
  14. {
  15. public class DelegationEnDataRepository : BaseRepository<Grp_DelegationEnData, Grp_DelegationEnData>
  16. {
  17. private readonly IMapper _mapper;
  18. public DelegationEnDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  19. {
  20. _mapper = mapper;
  21. }
  22. /// <summary>
  23. /// 团组英文资料操作(Status:1.新增,2.修改)
  24. /// </summary>
  25. /// <param name="dto"></param>
  26. /// <returns></returns>
  27. /// <exception cref="NotImplementedException"></exception>
  28. public async Task<Result> OpDelegationEnData(OpDelegationEnDataDto dto)
  29. {
  30. Result result = new Result() { Code = -2, Msg = "未知错误" };
  31. try
  32. {
  33. if (dto.Status == 1)//添加
  34. {
  35. string selectSql = string.Format(@"select * from Grp_DelegationEnData where Area='{0}' and Job='{1}' and IsDel='{2}'", dto.Area, dto.Job, 0);
  36. var grp_DelegationEnData = await _sqlSugar.SqlQueryable<Grp_DelegationEnData>(selectSql).FirstAsync();//查询是否存在
  37. if (grp_DelegationEnData != null)
  38. {
  39. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  40. }
  41. else//不存在,可添加
  42. {
  43. Grp_DelegationEnData _DelegationEnData = _mapper.Map<Grp_DelegationEnData>(dto);
  44. int id = await _sqlSugar.Insertable(_DelegationEnData).ExecuteReturnIdentityAsync();
  45. if (id == 0)
  46. {
  47. return result = new Result() { Code = -1, Msg = "添加失败!" };
  48. }
  49. return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  50. }
  51. }
  52. else if (dto.Status == 2)//修改
  53. {
  54. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationEnData
  55. {
  56. Area = dto.Area,
  57. Job = dto.Job,
  58. JobEn = dto.JobEn,
  59. DelegationSetting = dto.DelegationSetting,
  60. DelegationSettingEn = dto.DelegationSettingEn,
  61. CreateUserId = dto.CreateUserId,
  62. Remark = dto.Remark,
  63. });
  64. if (!res)
  65. {
  66. return result = new Result() { Code = -1, Msg = "修改失败!" };
  67. }
  68. return result = new Result() { Code = 0, Msg = "修改成功!", Data = new { Id = dto.Id } };
  69. }
  70. else
  71. {
  72. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  73. }
  74. }
  75. catch (Exception ex)
  76. {
  77. return result = new Result() { Code = -2, Msg = "程序错误!" };
  78. }
  79. }
  80. }
  81. }