StatisticRepo.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Linq;
  3. using BO.AppServer.Data.Entity;
  4. using Quadarax.Foundation.Core.Data;
  5. using Quadarax.Foundation.Core.Data.Domain;
  6. using Quadarax.Foundation.Core.Data.Interface.Domain;
  7. using Quadarax.Foundation.Core.Data.Repository;
  8. namespace BO.AppServer.Data.Repository
  9. {
  10. public class StatisticRepo : EntityRepository<long, Statistic>
  11. {
  12. public StatisticRepo(IUnitOfWork<DataDomain> unitOfWork) : base(unitOfWork)
  13. {
  14. }
  15. public Statistic GetCurrent()
  16. {
  17. var timestamp = DateTime.Now;
  18. var current = Query(Paging.NoPaging())
  19. .FirstOrDefault(x => x.Day == timestamp.Day && x.Month == timestamp.Month && x.Year == timestamp.Year);
  20. if (current != null)
  21. return current;
  22. current = New();
  23. current.Day = timestamp.Day;
  24. current.Month = timestamp.Month;
  25. current.Year = timestamp.Year;
  26. current.Created = DateTime.Now;
  27. Set(current);
  28. Commit();
  29. return current;
  30. }
  31. }
  32. }