DictionaryRepository.cs 1.6 KB

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