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 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; } } }