/// <summary>
        /// Saves a resource to the database. Either creates a new or updates existing record (depending on Id value).
        /// </summary>
        /// <param name="resource">Resource to save.</param>
        public void saveResource(Resource resource)
        {
            if (resource.Id > 0)
            {
                var entity = getResource(resource.Id);
                if (entity == null) throw new CrudException("Cannot find resource #" + resource.Id, SchedulerCodes.RESOURCE_NOT_FOUND);

                entity.Name = resource.Name;
                context.SaveChanges();
            }
            else
            {
                context.Resources.Add(resource);
                context.SaveChanges();

                // let's keep mapping from phantom to real Id
                AddedIds["resources"].Add(resource.PhantomId, resource.Id);
            }

            updateRevision();
        }
 /// <summary>
 /// Removes a resource from the database.
 /// </summary>
 /// <param name="resource">Resource to remove.</param>
 public void removeResource(Resource resource, bool force = false)
 {
     Resource entity = getResource(resource.Id);
     if (entity != null)
     {
         if (entity.events.Count > 0) throw new CrudException("Cannot remove assigned resource #" + resource.Id, SchedulerCodes.REMOVE_USED_RESOURCE);
         context.Resources.Remove(entity);
         context.SaveChanges();
         updateRevision();
     }
 }