AppConfigRegionModel.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 T GetItem(string name)
  33. {
  34. for (int i = 0; i < Items.Count; i++)
  35. {
  36. if (Items[i].GetUniqueName() == name)
  37. {
  38. return Items[i];
  39. }
  40. }
  41. return default(T);
  42. }
  43. public void OrderByNumber()
  44. {
  45. Items = Items.OrderBy(x => x.GetOrderNumber()).ToList();
  46. }
  47. public List<string> GetNames()
  48. {
  49. List<string> rs = new List<string>();
  50. foreach (var item in Items)
  51. {
  52. rs.Add(item.GetUniqueName());
  53. }
  54. return rs;
  55. }
  56. }
  57. }