CustomerInvoiceAddressApplicationService.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using System.Web.Mvc;
  5. using Abp.Application.Services.Dto;
  6. using Abp.Auditing;
  7. using Abp.Authorization;
  8. using Abp.Domain.Repositories;
  9. using Abp.Runtime.Caching;
  10. using IwbZero.AppServiceBase;
  11. using ShwasherSys.Authorization.Permissions;
  12. using ShwasherSys.CustomerInfo.InvoiceAddress.Dto;
  13. namespace ShwasherSys.CustomerInfo.InvoiceAddress
  14. {
  15. [AbpAuthorize]
  16. public class CustomerInvoiceAddressAppService : IwbZeroAsyncCrudAppService<CustomerInvoiceAddress, CustomerInvoiceAddressDto, int, IwbPagedRequestDto, CustomerInvoiceAddressCreateDto, CustomerInvoiceAddressUpdateDto >, ICustomerInvoiceAddressAppService
  17. {
  18. public CustomerInvoiceAddressAppService(
  19. ICacheManager cacheManager,
  20. IRepository<CustomerInvoiceAddress, int> repository) : base(repository, "InvoiceAddress")
  21. {
  22. CacheManager = cacheManager;
  23. }
  24. protected override bool KeyIsAuto { get; set; } = false;
  25. #region GetSelect
  26. [DisableAuditing]
  27. public override async Task<List<SelectListItem>> GetSelectList()
  28. {
  29. var list = await Repository.GetAllListAsync();
  30. var sList = new List<SelectListItem> {new SelectListItem {Text = @"请选择...", Value = "", Selected = true}};
  31. foreach (var l in list)
  32. {
  33. //sList.Add(new SelectListItem { Value = l.Id, Text = l. });
  34. }
  35. return sList;
  36. }
  37. [DisableAuditing]
  38. public override async Task<string> GetSelectStr()
  39. {
  40. var list = await Repository.GetAllListAsync();
  41. string str = "<option value=\"\" selected>请选择...</option>";
  42. foreach (var l in list)
  43. {
  44. //str += $"<option value=\"{l.Id}\">{l.}</option>";
  45. }
  46. return str;
  47. }
  48. #endregion
  49. #region CURD
  50. [AbpAuthorize(PermissionNames.PagesCustomerInfoCustomerInvoicesCreate)]
  51. public override async Task Create(CustomerInvoiceAddressCreateDto input)
  52. {
  53. await CreateEntity(input);
  54. }
  55. [AbpAuthorize(PermissionNames.PagesCustomerInfoCustomerInvoicesUpdate)]
  56. public override async Task Update(CustomerInvoiceAddressUpdateDto input)
  57. {
  58. await UpdateEntity(input);
  59. }
  60. [AbpAuthorize(PermissionNames.PagesCustomerInfoCustomerInvoicesDelete)]
  61. public override Task Delete(EntityDto<int> input)
  62. {
  63. return Repository.DeleteAsync(input.Id);
  64. }
  65. [DisableAuditing]
  66. [AbpAuthorize(PermissionNames.PagesCustomerInfoCustomerInvoices)]
  67. public override async Task<PagedResultDto<CustomerInvoiceAddressDto>> GetAll(IwbPagedRequestDto input)
  68. {
  69. var query = CreateFilteredQuery(input);
  70. query = ApplyFilter(query, input);
  71. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  72. query = ApplySorting(query, input);
  73. query = ApplyPaging(query, input);
  74. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  75. var dtoList = new PagedResultDto<CustomerInvoiceAddressDto>(totalCount, entities.Select(MapToEntityDto).ToList());
  76. return dtoList;
  77. }
  78. #region GetEntity/Dto
  79. /// <summary>
  80. /// 查询实体Dto
  81. /// </summary>
  82. /// <param name="input"></param>
  83. /// <returns></returns>
  84. [DisableAuditing]
  85. [AbpAuthorize(PermissionNames.PagesCustomerInfoCustomerInvoices)]
  86. public override async Task<CustomerInvoiceAddressDto> GetDto(EntityDto<int> input)
  87. {
  88. var entity = await GetEntity(input);
  89. return MapToEntityDto(entity);
  90. }
  91. /// <summary>
  92. /// 查询实体Dto
  93. /// </summary>
  94. /// <param name="id"></param>
  95. /// <returns></returns>
  96. [DisableAuditing]
  97. [AbpAuthorize(PermissionNames.PagesCustomerInfoCustomerInvoices)]
  98. public override async Task<CustomerInvoiceAddressDto> GetDtoById(int id)
  99. {
  100. var entity = await GetEntityById(id);
  101. return MapToEntityDto(entity);
  102. }
  103. /// <summary>
  104. /// 查询实体Dto(需指明自定义字段)
  105. /// </summary>
  106. /// <param name="no"></param>
  107. /// <returns></returns>
  108. [DisableAuditing]
  109. [AbpAuthorize(PermissionNames.PagesCustomerInfoCustomerInvoices)]
  110. public override async Task<CustomerInvoiceAddressDto> GetDtoByNo(string no)
  111. {
  112. var entity = await GetEntityByNo(no);
  113. return MapToEntityDto(entity);
  114. }
  115. /// <summary>
  116. /// 查询实体
  117. /// </summary>
  118. /// <param name="input"></param>
  119. /// <returns></returns>
  120. [DisableAuditing]
  121. [AbpAuthorize(PermissionNames.PagesCustomerInfoCustomerInvoices)]
  122. public override async Task<CustomerInvoiceAddress> GetEntity(EntityDto<int> input)
  123. {
  124. var entity = await GetEntityById(input.Id);
  125. return entity;
  126. }
  127. /// <summary>
  128. /// 查询实体
  129. /// </summary>
  130. /// <param name="id"></param>
  131. /// <returns></returns>
  132. [DisableAuditing]
  133. [AbpAuthorize(PermissionNames.PagesCustomerInfoCustomerInvoices)]
  134. public override async Task<CustomerInvoiceAddress> GetEntityById(int id)
  135. {
  136. return await Repository.FirstOrDefaultAsync(a=>a.Id==id);
  137. }
  138. /// <summary>
  139. /// 查询实体(需指明自定义字段)
  140. /// </summary>
  141. /// <param name="no"></param>
  142. /// <returns></returns>
  143. [DisableAuditing]
  144. [AbpAuthorize(PermissionNames.PagesCustomerInfoCustomerInvoices)]
  145. public override async Task<CustomerInvoiceAddress> GetEntityByNo(string no)
  146. {
  147. //CheckGetPermission();
  148. if (string.IsNullOrEmpty(KeyFiledName))
  149. {
  150. ThrowError("NoKeyFieldName");
  151. }
  152. return await base.GetEntityByNo(no);
  153. }
  154. #endregion
  155. #region Hide
  156. ///// <summary>
  157. ///// 根据给定的<see cref="IwbPagedRequestDto"/>创建 <see cref="IQueryable{CustomerInvoiceAddress}"/>过滤查询.
  158. ///// </summary>
  159. ///// <param name="input">The input.</param>
  160. //protected override IQueryable<CustomerInvoiceAddress> CreateFilteredQuery(IwbPagedRequestDto input)
  161. //{
  162. // var query = Repository.GetAll();
  163. // var pagedInput = input as IIwbPagedRequest;
  164. // if (pagedInput == null)
  165. // {
  166. // return query;
  167. // }
  168. // if (!string.IsNullOrEmpty(pagedInput.KeyWords))
  169. // {
  170. // object keyWords = pagedInput.KeyWords;
  171. // LambdaObject obj = new LambdaObject()
  172. // {
  173. // FieldType = (LambdaFieldType)pagedInput.FieldType,
  174. // FieldName = pagedInput.KeyField,
  175. // FieldValue = keyWords,
  176. // ExpType = (LambdaExpType)pagedInput.ExpType
  177. // };
  178. // var exp = obj.GetExp<CustomerInvoiceAddress>();
  179. // query = exp != null ? query.Where(exp) : query;
  180. // }
  181. // if (pagedInput.SearchList != null && pagedInput.SearchList.Count > 0)
  182. // {
  183. // List<LambdaObject> objList = new List<LambdaObject>();
  184. // foreach (var o in pagedInput.SearchList)
  185. // {
  186. // if (string.IsNullOrEmpty(o.KeyWords))
  187. // continue;
  188. // object keyWords = o.KeyWords;
  189. // objList.Add(new LambdaObject
  190. // {
  191. // FieldType = (LambdaFieldType)o.FieldType,
  192. // FieldName = o.KeyField,
  193. // FieldValue = keyWords,
  194. // ExpType = (LambdaExpType)o.ExpType
  195. // });
  196. // }
  197. // var exp = objList.GetExp<CustomerInvoiceAddress>();
  198. // query = exp != null ? query.Where(exp) : query;
  199. // }
  200. // return query;
  201. //}
  202. //protected override IQueryable<CustomerInvoiceAddress> ApplySorting(IQueryable<CustomerInvoiceAddress> query, IwbPagedRequestDto input)
  203. //{
  204. // return query.OrderBy(a => a.No);
  205. //}
  206. //protected override IQueryable<CustomerInvoiceAddress> ApplyPaging(IQueryable<CustomerInvoiceAddress> query, IwbPagedRequestDto input)
  207. //{
  208. // if (input is IPagedResultRequest pagedInput)
  209. // {
  210. // return query.Skip(pagedInput.SkipCount).Take(pagedInput.MaxResultCount);
  211. // }
  212. // return query;
  213. //}
  214. #endregion
  215. #endregion
  216. }
  217. }