12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using EMIS.DataLogic.Repositories;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace EMIS.CommonLogic
- {
- public class TestServices: BaseServices, ITestServices
- {
- public TestOperateRepository TestOperateRepository { get; set; }
- public UserRepository UserRepository { get; set; }
- public List<TestOperateView> GetTestOperateViewList()
- {
- var query = from test in TestOperateRepository.Entities
- from user in UserRepository.Entities.Where(x => x.UserID == test.UserID)
- select new TestOperateView
- {
- OperateID = test.OperateID,
- UserID = test.UserID,
- UserName = user.Name,
- StartTime = test.StartTime,
- EndTime = test.EndTime,
- CreateTime = test.CreateTime,
- CreateUserID = test.CreateUserID,
- ModifyTime = test.ModifyTime,
- ModifyUserID = test.ModifyUserID
- };
- return query.OrderByDescending(x => x.CreateTime).ToList();
- }
- public TestOperateView GetTestOperateView(Guid? operateID) {
- var query = from test in TestOperateRepository.Entities.Where(x => x.OperateID == operateID)
- from user in UserRepository.Entities.Where(x => x.UserID == test.UserID)
- select new TestOperateView
- {
- OperateID = test.OperateID,
- UserID = test.UserID,
- UserName = user.Name,
- StartTime = test.StartTime,
- EndTime = test.EndTime,
- CreateTime = test.CreateTime,
- CreateUserID = test.CreateUserID,
- ModifyTime = test.ModifyTime,
- ModifyUserID = test.ModifyUserID
- };
- return query.ToList().FirstOrDefault();
- }
- public void Start(TestOperateView testOperateView) {
- TestOperate testOperate = new TestOperate();
- testOperate.OperateID = Guid.NewGuid();
- testOperate.UserID = testOperateView.UserID.Value;
- testOperate.StartTime = DateTime.Now;
- testOperate.CreateUserID = testOperateView.UserID;
- testOperate.CreateTime = DateTime.Now;
- testOperate.ModifyUserID = testOperateView.UserID;
- testOperate.ModifyTime = DateTime.Now;
- UnitOfWork.Add(testOperate);
- UnitOfWork.Commit();
- //return testOperate.OperateID;
- }
- public void End(Guid? userID)
- {
- var dbtestOperate = TestOperateRepository.Entities.Where(x => x.UserID == userID && x.EndTime == null).FirstOrDefault();
- dbtestOperate.EndTime = DateTime.Now;
- dbtestOperate.ModifyUserID = userID;
- dbtestOperate.ModifyTime = DateTime.Now;
- UnitOfWork.Update(dbtestOperate);
- UnitOfWork.Commit();
- //return dbtestOperate.OperateID;
- }
- public bool IsEnd(Guid? userID)
- {
- var dbtestOperate = TestOperateRepository.Entities.Where(x => x.UserID == userID && x.EndTime == null).FirstOrDefault();
- if (dbtestOperate != null)
- {
- return false;
- }
- return true;
- }
- }
- }
|