AssetsService.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Microsoft.EntityFrameworkCore;
  2. using Microsoft.Extensions.Logging;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using Winsoft.GOV.XF.WebApi.WXCore.Data;
  8. using Winsoft.GOV.XF.WebApi.WXCore.Models;
  9. namespace Winsoft.GOV.XF.WebApi.WXCore.Services
  10. {
  11. public class AssetsService : BaseService
  12. {
  13. public AssetsService(XFDbContext context, ILoggerFactory loggerFactory):base(context, loggerFactory)
  14. {
  15. }
  16. public async Task Add(Asset a)
  17. {
  18. await _context.AddAsync<Asset>(a);
  19. await _context.SaveChangesAsync();
  20. }
  21. public async Task<IEnumerable<Asset>> GetByBundleId(string id)
  22. {
  23. Guid g;
  24. if (!String.IsNullOrWhiteSpace(id) && Guid.TryParse(id, out g))
  25. return await _context.Assets.Where(m => m.BundleId == g).ToListAsync<Asset>();
  26. else
  27. {
  28. Logger.LogError(String.Format("id:{0};id不存在或不能转换为guid", id));
  29. }
  30. return null;
  31. }
  32. }
  33. }