AppConfigRegionModel.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using Azylee.Core.DataUtils.CollectionUtils;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace Azylee.Core.AppUtils.AppConfigUtils.AppConfigModels
  7. {
  8. public class AppConfigRegionModel<T> where T : IAppConfigItemModel
  9. {
  10. public List<T> Items { get; set; }
  11. public AppConfigRegionModel()
  12. {
  13. this.Items = new List<T>();
  14. }
  15. public bool HasItems()
  16. {
  17. return Ls.Ok(Items);
  18. }
  19. public void AddItem(T item, bool overwrite = false)
  20. {
  21. bool repeat = false;
  22. for (int i = 0; i < Items.Count; i++)
  23. {
  24. if (Items[i].GetUniqueName() == item.GetUniqueName())
  25. {
  26. if (overwrite) { Items[i] = item; }
  27. repeat = true;
  28. }
  29. }
  30. if (!repeat) { this.Items.Add(item); }
  31. }
  32. public void OrderByNumber()
  33. {
  34. Items = Items.OrderBy(x => x.GetOrderNumber()).ToList();
  35. }
  36. }
  37. }