CcsActionAddressRepository.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 
  2. using IMCS.CCS.Entitys;
  3. using Microsoft.EntityFrameworkCore;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. namespace IMCS.CCS.Repository
  9. {
  10. public class CcsActionAddressRepository : ICcsActionAddressRepository
  11. {
  12. private readonly CcsContext _context;
  13. public CcsActionAddressRepository(CcsContext context)
  14. {
  15. _context = context;
  16. }
  17. //查询列表
  18. public List<CcsActionAddress> GetList(CcsActionAddress vo)
  19. {
  20. IQueryable<CcsActionAddress> actions = _context.CcsActionAddress;
  21. if (vo.ActionId != null)
  22. {
  23. actions = actions.Where(x => x.ActionId == vo.ActionId);
  24. }
  25. if (!string.IsNullOrEmpty(vo.Type))
  26. {
  27. actions = actions.Where(x => x.Type == vo.Type);
  28. }
  29. return actions.OrderBy(x => x.Sort).ToList();
  30. }
  31. //查询详情
  32. public async Task<CcsActionAddress> GetById(int id)
  33. {
  34. CcsActionAddress action = await _context.CcsActionAddress.FindAsync(id);
  35. return action;
  36. }
  37. //添加详情
  38. public async Task<bool> Create(CcsActionAddress vo)
  39. {
  40. _context.CcsActionAddress.Add(vo);
  41. await _context.SaveChangesAsync();
  42. return true;
  43. }
  44. //更新详情
  45. public async Task<bool> Update(CcsActionAddress vo)
  46. {
  47. _context.Entry(vo).State = EntityState.Modified;
  48. try
  49. {
  50. await _context.SaveChangesAsync();
  51. }
  52. catch (DbUpdateConcurrencyException)
  53. {
  54. throw;
  55. }
  56. return true;
  57. }
  58. }
  59. }