ExportPassJournalItem Translate(PassJournal tableItem)
		{
			return new ExportPassJournalItem
			{
				UID = tableItem.UID,
				EmployeeUID = tableItem.EmployeeUID.GetValueOrDefault(),
				EnterDateTime = tableItem.EnterTime,
				ExitDateTime = tableItem.ExitTime != null ? tableItem.ExitTime.Value : new DateTime(),
				ZoneUID = tableItem.ZoneUID
			};
		}
		public OperationResult<bool> AddCustomPassJournal(Guid uid, Guid employeeUID, Guid zoneUID, DateTime enterTime, DateTime exitTime)
		{
			return DbServiceHelper.InTryCatch(() =>
			{
				var passJournalItem = new PassJournal();
				passJournalItem.UID = uid;
				passJournalItem.EmployeeUID = employeeUID.EmptyToNull();
				passJournalItem.ZoneUID = zoneUID;
				passJournalItem.EnterTime = enterTime.CheckDate();
				passJournalItem.ExitTime = exitTime.CheckDate();
				if (IsIntersection(passJournalItem))
					throw new Exception("Невозможно добавить пересекающийся интервал");
				Context.PassJournals.Add(passJournalItem);
				Context.SaveChanges();
				return true;
			});
		}
		public OperationResult<bool> AddPassJournal(Guid employeeUID, Guid zoneUID)
		{
			return DbServiceHelper.InTryCatch(() =>
			{
				var exitPassJournal = Context.PassJournals.FirstOrDefault(x => x.EmployeeUID == employeeUID && x.ExitTime == null);
				if (exitPassJournal != null)
				{
					exitPassJournal.ExitTime = DateTime.Now;
				}
				if (zoneUID != Guid.Empty)
				{
					var enterPassJournal = new PassJournal();
					enterPassJournal.UID = Guid.NewGuid();
					enterPassJournal.EmployeeUID = employeeUID;
					enterPassJournal.ZoneUID = zoneUID;
					enterPassJournal.EnterTime = DateTime.Now;
					enterPassJournal.ExitTime = null;
					Context.PassJournals.Add(enterPassJournal);
				}
				Context.SaveChanges();
				return true;
			});
		}
		ExportPassJournalItem Translate(PassJournal tableItem, List<Employee> employees)
		{
			var employee = employees.FirstOrDefault(x => x.UID == tableItem.EmployeeUID);
			var zone = GKManager.SKDZones.FirstOrDefault(x => x.UID == tableItem.ZoneUID);
			return new ExportPassJournalItem
			{
				UID = tableItem.UID,
				EmployeeUID = tableItem.EmployeeUID != null ? tableItem.EmployeeUID.Value : Guid.Empty,
				EmployeeFIO = employee != null ? employee.LastName + " " + employee.FirstName + " " + employee.SecondName : "",
				EnterDateTime = tableItem.EnterTime,
				ExitDateTime = tableItem.ExitTime != null ? tableItem.ExitTime.Value : new DateTime(),
				ZoneUID = tableItem.ZoneUID,
				ZoneNo = zone != null ? zone.No : -1
			};
		}
		bool IsIntersection(PassJournal passJournalItem)
		{
			return Context.PassJournals.Any(x => x.UID != passJournalItem.UID &&
				x.EmployeeUID == passJournalItem.EmployeeUID &&
				(x.EnterTime < passJournalItem.EnterTime && x.ExitTime > passJournalItem.EnterTime ||
					x.EnterTime < passJournalItem.ExitTime && x.ExitTime > passJournalItem.ExitTime));
		}
		public void InsertPassJournalTestData()
		{
			IEnumerable<ShortEmployee> employees = null;
			employees = DbService.EmployeeTranslator.ShortTranslator.Get(new EmployeeFilter()).Result;
			var zoneUID = GKManager.Zones.FirstOrDefault().UID;

			Context.PassJournals.RemoveRange(Context.PassJournals);

			var random = new Random();
			foreach (var employee in employees)
			{
				for (int day = 0; day < 100; day++)
				{
					var dateTime = DateTime.Now.AddDays(-day);

					var seconds = new List<int>();
					var count = random.Next(0, 5);
					for (int i = 0; i < count * 2; i++)
					{
						var totalSeconds = random.Next(0, 24 * 60 * 60);
						seconds.Add(totalSeconds);
					}
					seconds.Sort();

					for (int i = 0; i < count * 2; i += 2)
					{
						var startTimeSpan = TimeSpan.FromSeconds(seconds[i]);
						var endTimeSpan = TimeSpan.FromSeconds(seconds[i + 1]);

						var passJournal = new PassJournal();
						passJournal.UID = Guid.NewGuid();
						passJournal.EmployeeUID = employee.UID;
						passJournal.ZoneUID = zoneUID;
						passJournal.EnterTime = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, startTimeSpan.Hours, startTimeSpan.Minutes, startTimeSpan.Seconds);
						passJournal.ExitTime = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, endTimeSpan.Hours, endTimeSpan.Minutes, endTimeSpan.Seconds);
						Context.PassJournals.Add(passJournal);
					}
				}
			}
			Context.SaveChanges();
		}