TestServices.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using EMIS.DataLogic.Repositories;
  2. using EMIS.Entities;
  3. using EMIS.ViewModel;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace EMIS.CommonLogic
  10. {
  11. public class TestServices: BaseServices, ITestServices
  12. {
  13. public TestOperateRepository TestOperateRepository { get; set; }
  14. public UserRepository UserRepository { get; set; }
  15. public List<TestOperateView> GetTestOperateViewList()
  16. {
  17. var query = from test in TestOperateRepository.Entities
  18. from user in UserRepository.Entities.Where(x => x.UserID == test.UserID)
  19. select new TestOperateView
  20. {
  21. OperateID = test.OperateID,
  22. UserID = test.UserID,
  23. UserName = user.Name,
  24. StartTime = test.StartTime,
  25. EndTime = test.EndTime,
  26. CreateTime = test.CreateTime,
  27. CreateUserID = test.CreateUserID,
  28. ModifyTime = test.ModifyTime,
  29. ModifyUserID = test.ModifyUserID
  30. };
  31. return query.OrderByDescending(x => x.CreateTime).ToList();
  32. }
  33. public TestOperateView GetTestOperateView(Guid? operateID) {
  34. var query = from test in TestOperateRepository.Entities.Where(x => x.OperateID == operateID)
  35. from user in UserRepository.Entities.Where(x => x.UserID == test.UserID)
  36. select new TestOperateView
  37. {
  38. OperateID = test.OperateID,
  39. UserID = test.UserID,
  40. UserName = user.Name,
  41. StartTime = test.StartTime,
  42. EndTime = test.EndTime,
  43. CreateTime = test.CreateTime,
  44. CreateUserID = test.CreateUserID,
  45. ModifyTime = test.ModifyTime,
  46. ModifyUserID = test.ModifyUserID
  47. };
  48. return query.ToList().FirstOrDefault();
  49. }
  50. public void Start(TestOperateView testOperateView) {
  51. TestOperate testOperate = new TestOperate();
  52. testOperate.OperateID = Guid.NewGuid();
  53. testOperate.UserID = testOperateView.UserID.Value;
  54. testOperate.StartTime = DateTime.Now;
  55. testOperate.CreateUserID = testOperateView.UserID;
  56. testOperate.CreateTime = DateTime.Now;
  57. testOperate.ModifyUserID = testOperateView.UserID;
  58. testOperate.ModifyTime = DateTime.Now;
  59. UnitOfWork.Add(testOperate);
  60. UnitOfWork.Commit();
  61. //return testOperate.OperateID;
  62. }
  63. public void End(Guid? userID)
  64. {
  65. var dbtestOperate = TestOperateRepository.Entities.Where(x => x.UserID == userID && x.EndTime == null).FirstOrDefault();
  66. dbtestOperate.EndTime = DateTime.Now;
  67. dbtestOperate.ModifyUserID = userID;
  68. dbtestOperate.ModifyTime = DateTime.Now;
  69. UnitOfWork.Update(dbtestOperate);
  70. UnitOfWork.Commit();
  71. //return dbtestOperate.OperateID;
  72. }
  73. public bool IsEnd(Guid? userID)
  74. {
  75. var dbtestOperate = TestOperateRepository.Entities.Where(x => x.UserID == userID && x.EndTime == null).FirstOrDefault();
  76. if (dbtestOperate != null)
  77. {
  78. return false;
  79. }
  80. return true;
  81. }
  82. }
  83. }