public Boolean InsertDevice(ChildDevices childDevices)
        {
            // define defaults blocked classes
            if (childDevices.BlockedURLs == null)
                childDevices.BlockedURLs = ConfigurationManager.AppSettings["DefaultBlockedURLs"];

            var device = new Device
                         {
                             LicenseId = childDevices.LicenseId,
                             TbpId = childDevices.Tbpid,
                             Name = childDevices.Name,
                             Avatar = childDevices.Avatar,
                             OnlineTimeFrames = childDevices.OnlineTimeFrames,
                             OnlineWebTimeFrames = childDevices.OnlineWebTimeFrames,
                             BlockedUrls = childDevices.BlockedURLs,
                             Obs = "",
                             Created = DateTime.UtcNow,
                             Updated = DateTime.UtcNow,
                             Version = "1.0",
                             Type = childDevices.Type,
                             ChildDevices = new Collection<ChildDevice>
                                            {
                                                new ChildDevice
                                                {
                                                    ChildId = childDevices.ChildId
                                                }
                                            }
                         };

            using (var context = new CustomerInfoRepository())
            {
                context.Devices.Add(device);
                try
                {
                    context.SaveChanges();
                }
                catch (Exception)
                {
                    return false;
                }
            }

            var repository = new CustomerRepository();
            repository.InsertBlocker(childDevices.LicenseId, childDevices.ChildId, device.Id, childDevices.BlockedURLs);
            repository.InsertOnlineTime(childDevices.LicenseId, childDevices.ChildId, device.Id, childDevices.OnlineTimeFrames, childDevices.OnlineWebTimeFrames);

            return true;
        }
        /// <summary>
        /// Update New Device
        /// </summary>
        public Device UpdateDevice(ChildDevices childDevices)
        {
            using (var context = new CustomerInfoRepository())
            {
                var updating = context.Devices.SingleOrDefault(x => x.Id == childDevices.Id);
                if (updating != null)
                {
                    updating.Updated = DateTime.UtcNow;

                    foreach (var childDevice in updating.ChildDevices.ToArray())
                    {
                        context.ChildDevices.Remove(childDevice);
                    }

                    var newChildDevice = new ChildDevice
                                 {
                                     DeviceId = updating.Id,
                                     ChildId = childDevices.ChildId
                                 };
                    context.ChildDevices.Add(newChildDevice);
                    updating.ChildDevices.Add(newChildDevice);
                    if (childDevices.Name != null) updating.Name = childDevices.Name;
                    if (childDevices.Avatar != null) updating.Avatar = childDevices.Avatar;
                    if (childDevices.OnlineTimeFrames != null) updating.OnlineTimeFrames = childDevices.OnlineTimeFrames;
                    if (childDevices.OnlineWebTimeFrames != null) updating.OnlineWebTimeFrames = childDevices.OnlineWebTimeFrames;
                    if (childDevices.BlockedURLs != null) updating.BlockedUrls = childDevices.BlockedURLs;
                    if (childDevices.Obs != null) updating.Obs = childDevices.Obs;
                    if (childDevices.Type != null) updating.Type = childDevices.Type;

                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception)
                    {
                        return null;
                    }

                    var repository = new CustomerRepository();
                    repository.UpdateBlocker(childDevices.LicenseId, childDevices.ChildId, childDevices.Id, childDevices.BlockedURLs);
                    repository.UpdateOnlineTime(childDevices.LicenseId, childDevices.ChildId, childDevices.Id, childDevices.OnlineTimeFrames, childDevices.OnlineWebTimeFrames);
                    return updating;
                }
                else
                {
                    return null;
                }
            }
        }
 public void UpdateDeviceTest()
 {
     var repository = new CustomerRepositoryHelper();
     var device = new ChildDevices
                  {
                      Id = 1,
                      LicenseId = "11",
                      Tbpid = "42232",
                      ChildId = 2,
                      Name = "Name",
                      Avatar = "avatar",
                      OnlineTimeFrames = "otf",
                      OnlineWebTimeFrames = "owtf"
                  };
     Console.WriteLine(repository.UpdateDevice(device));
 }