TasksQzServices.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using AutoMapper;
  2. using Ropin.Inspection.Common.Accessor.Interface;
  3. using Ropin.Inspection.Model.Entities;
  4. using Ropin.Inspection.Repository.Interface;
  5. using Ropin.Inspection.Service.Interface;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Linq.Expressions;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace Ropin.Inspection.Service
  13. {
  14. public class TasksQzServices : ITasksQzServices
  15. {
  16. private readonly ITasksQzRepository _repository;
  17. private readonly IMapper _mapper;
  18. private readonly IClaimsAccessor _claims;
  19. public TasksQzServices(IClaimsAccessor claims, ITasksQzRepository repository, IMapper mapper)
  20. {
  21. _repository = repository;
  22. _mapper = mapper;
  23. _claims = claims;
  24. }
  25. public async Task<IEnumerable<TasksQz>> GetAllAsync()
  26. {
  27. var pagedList = await _repository.GetAllAsync();
  28. return pagedList;
  29. }
  30. public async Task CreateOneAsync(TasksQz viewModel)
  31. {
  32. viewModel.CreateBy = _claims.ApiUserId;
  33. viewModel.CreateTime = DateTime.Now;
  34. viewModel.IsDeleted = false;
  35. _repository.Create(viewModel);
  36. var result = await _repository.SaveAsync();
  37. if (!result)
  38. {
  39. throw new Exception("创建失败");
  40. }
  41. }
  42. public async Task DeleteAsync(Guid id)
  43. {
  44. var content = await _repository.GetByIdAsync(id);
  45. if (content == null)
  46. {
  47. throw new Exception("没有此任务");
  48. }
  49. content.IsDeleted = true;
  50. _repository.Update(content);
  51. var result = await _repository.SaveAsync();
  52. if (!result)
  53. {
  54. throw new Exception("删除失败");
  55. }
  56. }
  57. public async Task<TasksQz> GetByIdAsync(Guid id)
  58. {
  59. var content = await _repository.GetByIdAsync(id);
  60. return content;
  61. }
  62. public Task<bool> IsExistAsync(Guid id)
  63. {
  64. throw new NotImplementedException();
  65. }
  66. public Task<int> UpdateOneAsync(TasksQz viewModel, params string[] fields)
  67. {
  68. throw new NotImplementedException();
  69. }
  70. public async Task UpdateAsync(Guid id, TasksQz updateModel)
  71. {
  72. var content = await _repository.GetByIdAsync(id);
  73. if (content == null)
  74. {
  75. throw new Exception("没有此任务");
  76. }
  77. //content.C_LastUpdatedBy = _claims.ApiUserId;
  78. //content.D_LastUpdatedOn = DateTime.Now;
  79. //_mapper.Map(updateModel, content, typeof(TispRouteUpdateViewModel), typeof(TISP_Route));
  80. _repository.Update(content);
  81. var result = await _repository.SaveAsync();
  82. if (!result)
  83. {
  84. throw new Exception("更新失败");
  85. }
  86. }
  87. //public async Task<IEnumerable<TasksQz>> GetContentsConditionAsync(Expression<Func<T, bool>> whereLambda, string ordering, bool IsPagination, int pageIndex, int pageSize)
  88. //{
  89. // var predicate = PredicateBuilder.New<TasksQz>(true);//查询条件,推荐后台使用这种方式灵活筛选
  90. // #region 添加条件查询
  91. // predicate = predicate.And(i => i.C_Status.Equals("1"));
  92. // if (!string.IsNullOrEmpty(searchModel.C_Name))
  93. // {
  94. // predicate = predicate.And(i => i.C_Name.Contains(searchModel.C_Name));
  95. // }
  96. // #endregion
  97. // var list = await _repository.GetPageAsync(predicate, "C_Name,-D_CreateOn", searchModel.IsPagination, searchModel.PageIndex, searchModel.PageSize);
  98. // searchModel.TotalCount = list.Totals;
  99. // var dtoList = _mapper.Map<List<TISP_Content>, List<TispContentViewModel>>(list.Rows);
  100. // return dtoList;
  101. //}
  102. }
  103. }