WcsActionAddressRepository.cs 1.9 KB

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