WcsActionRepository.cs 1.9 KB

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