DefaultAppGuidsCreator.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Linq;
  2. using WeApp.BaseInfo;
  3. using WeApp.EF;
  4. using IwbZero.Authorization.Base.SystemInfo;
  5. namespace WeApp.SeedData
  6. {
  7. public class DefaultAppGuidsCreator
  8. {
  9. private readonly WeAppDbContext _context;
  10. public DefaultAppGuidsCreator(WeAppDbContext context)
  11. {
  12. _context = context;
  13. }
  14. public void Create()
  15. {
  16. _context.TruncateTable("[dbo].[Sys_AppGuids]");
  17. AddAppGuidIfNotExists((short)AppGuidType.UserNo);
  18. AddAppGuidIfNotExists((short)AppGuidType.Guest);
  19. AddAppGuidIfNotExists((short)AppGuidType.DataLib, 1000);
  20. }
  21. private void AddAppGuidIfNotExists(short type, int start = 100000, short step = 1)
  22. {
  23. if (_context.SysAppGuids.Any(s => s.IdType == type))
  24. return;
  25. _context.SysAppGuids.Add(new SysAppGuid()
  26. {
  27. IdType = type,
  28. LastId = start,
  29. Step = step,
  30. });
  31. _context.SaveChanges();
  32. }
  33. }
  34. }