/// <exception cref="InvalidClientDataException">On invalid client input vales.</exception>
 public SerializableNtwkNode CreateNode(SerializableNtwkNode node, int parentID = 0)
 {
     if (node.ID == 0)
     {
         var modelNode = new NtwkNode();
         try {
             modelNode.CopyFromSerializable(node);
         }
         catch (FormatException) {
             throw new InvalidClientDataException("Incorrect ip address format.");
         }
         if (parentID == 0) //root children
         {
             db.Nodes.Add(modelNode);
             db.SaveChanges();
         }
         else
         {
             var bruddas = db.Nodes.Include(n => n.Children)
                           .SingleOrDefault(n => n.ID == parentID)?.Children;
             if (bruddas == null)
             {
                 throw new InvalidClientDataException(
                           "Trying to create node with nonexisting parent.");
             }
             bruddas.Add(modelNode);
             db.SaveChanges();
         }
         return(db.Nodes.AsNoTracking()
                .Include(n => n.Parent)
                .Single(n => n.ID == modelNode.ID)
                .IntoSerializable());
     }
     else
     {
         throw new InvalidClientDataException(
                   "Only entries with ID=0 are accepted.");
     }
 }
 /// <exception cref="InvalidClientDataException">On invalid client input vales.</exception>
 public void UpdateNode(SerializableNtwkNode node, int parentID = 0)
 {
     if (node.ID != 0)
     {
         NtwkNode entry = db.Nodes
                          .Include(n => n.Parent)
                          .SingleOrDefault(n => n.ID == node.ID);
         NtwkNode parent = null;
         if (entry == null)
         {
             throw new InvalidClientDataException(
                       "Can't update nonexisting node");
         }
         if (parentID != 0)
         {
             parent = db.Nodes.Find(parentID);
             if (parent == null)
             {
                 throw new InvalidClientDataException(
                           "Trying to set node's parent to nonexistent entry."
                           );
             }
         }
         try {
             entry.CopyFromSerializable(node);
         }
         catch (FormatException) {
             throw new InvalidClientDataException("Incorrect ip address format.");
         }
         if (parent != null)
         {
             entry.Parent = parent;
         }
     }
     db.SaveChanges();
 }