CcsActionRepository.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 CcsActionRepository : ICcsActionRepository
  11. {
  12. private readonly CcsContext _context;
  13. public CcsActionRepository(CcsContext context)
  14. {
  15. _context = context;
  16. }
  17. //查询列表
  18. public List<CcsAction> GetList(CcsAction vo)
  19. {
  20. IQueryable<CcsAction> actions = _context.CcsAction;
  21. if (!string.IsNullOrEmpty(vo.OperateType))
  22. {
  23. actions = actions.Where(x => x.OperateType.Equals(vo.OperateType));
  24. }
  25. if (!string.IsNullOrEmpty(vo.OrderIndex))
  26. {
  27. actions = actions.Where(x => x.OrderIndex.Equals(vo.OrderIndex));
  28. }
  29. if (!string.IsNullOrEmpty(vo.Ip))
  30. {
  31. actions = actions.Where(x => x.Ip.Equals(vo.Ip));
  32. }
  33. return actions.ToList();
  34. }
  35. //查询详情
  36. public async Task<CcsAction> GetById(int id)
  37. {
  38. CcsAction action = await _context.CcsAction.FindAsync(id);
  39. return action;
  40. }
  41. //添加详情
  42. public async Task<bool> Create(CcsAction vo)
  43. {
  44. _context.CcsAction.Add(vo);
  45. await _context.SaveChangesAsync();
  46. return true;
  47. }
  48. //更新详情
  49. public async Task<bool> Update(CcsAction vo)
  50. {
  51. _context.Entry(vo).State = EntityState.Modified;
  52. try
  53. {
  54. await _context.SaveChangesAsync();
  55. }
  56. catch (DbUpdateConcurrencyException)
  57. {
  58. throw;
  59. }
  60. return true;
  61. }
  62. }
  63. }