public void TestSimpleSave()
        {
            DeviceSimulator deviceSimulator = new DeviceSimulator();
            deviceSimulator.Description = "XXXXX";

            var sessionFactory = CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    for (int i = 0; i < 10; i++)
                    {
                        deviceSimulator.AddSimDevice(new SimDevice
                        {
                            Imei = "SIM" + i.ToString("0###"),
                        });
                    }

                    foreach (var item in deviceSimulator.SimDevices)
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            item.AddPacket(new Packet
                            {
                                Description = "Desc" + i.ToString("0###")
                            });
                        }
                    }                            

                    session.SaveOrUpdate(deviceSimulator);
                    transaction.Commit();
                }
            }
        }
        public DeviceSimulator GetByIdDeviceSimulator(int id)
        {
            var deviceSimulator = new DeviceSimulator();

            var query = _session.Query<DeviceSimulator>().GetById(id);
            deviceSimulator = query.FirstOrDefault();

            return deviceSimulator;
        }
        public DeviceSimulator GetByIdDeviceSimulatorIncludeChild(int id)
        {
            var deviceSimulator = new DeviceSimulator();

            var query = from d in _session.Query<DeviceSimulator>()
                        where d.Id == id
                        select d;

            deviceSimulator = query.FirstOrDefault();

            return deviceSimulator;
        }
        public int SaveCreateSimDevices(ObservableCollection<SimDeviceViewModel> simDeviceViewModel, HeaderDevicesSimulatorViewModel headerDevicesSimulatorViewModel)
        {
            int result = 0;
            try
            {
                DeviceSimulator deviceSimulator = new DeviceSimulator();
                deviceSimulator.Description = headerDevicesSimulatorViewModel.HeadName;
                deviceSimulator.Status = headerDevicesSimulatorViewModel.Status;

                foreach (var item in simDeviceViewModel)
                {
                    deviceSimulator.AddSimDevice(new SimDevice
                    {
                        Imei = item.Imei,
                        Description = item.Description,
                        Status = item.Status,
                        SendComplete = item.SendComplete,
                        SendTotal = item.SendTotal,
                        SendTime = item.SendTime
                    });
                }

                _session.SaveOrUpdate(deviceSimulator);
                result = deviceSimulator.Id;
            }
            catch (Exception ex)
            {
                result = 0;
            }
            return result;
        }
        public DeviceSimulatorModel getSimDevicesByDeviceSimulatorId(int id)
        {
            var deviceSimulatorModel = new DeviceSimulatorModel();
            _header = _deviceSimService.GetByIdDeviceSimulatorIncludeChild(id);

            if (_header != null)
            {
                deviceSimulatorModel.Id = _header.Id;
                deviceSimulatorModel.Description = _header.Description;
                deviceSimulatorModel.Status = _header.Status;

                _header.SimDevices.ToList().ForEach(item =>
                {
                    deviceSimulatorModel.SimDeviceViewModel.Add(new SimDeviceViewModel
                    {
                        Id = item.Id,
                        Imei = item.Imei,
                        Description = item.Description,
                        SendTime = item.SendTime,
                        SendTotal = item.SendTotal,
                        Status = item.Status,
                        SendComplete = item.SendComplete,
                    });
                });

            }
            return deviceSimulatorModel;
        }