public int AddResource(NodeResource resource, HttpPostedFileBase file)
        {
            var node = GetDbContext().Nodes.SingleOrDefault(n => n.Id == resource.NodeId);
            var path = Path.Combine(GetCoursePath(node.CourseId), "Node");
            path = Path.Combine(path, resource.NodeId.Value.ToString());
            path = Path.Combine(path, "Images");
            
            resource.Path = "Node/" + resource.NodeId + "/Images/" + file.FileName;

            if(!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            file.SaveAs(Path.Combine(path, file.FileName));
            
            var db = GetDbContext();

            db.NodeResources.InsertOnSubmit(resource);
            db.SubmitChanges();


            return resource.Id;
        }
        public void UpdateResource(int id, NodeResource resource)
        {
            var db = GetDbContext();

            var oldRes = db.NodeResources.Single(n => n.Id == id);

            oldRes.Name = resource.Name;
            oldRes.Type = resource.Type;
            oldRes.Path = resource.Path;

            db.SubmitChanges();
        }
 partial void DeleteNodeResource(NodeResource instance);
 partial void UpdateNodeResource(NodeResource instance);
 partial void InsertNodeResource(NodeResource instance);
		private void detach_NodeResources(NodeResource entity)
		{
			this.SendPropertyChanging();
			entity.Node = null;
		}
		private void attach_NodeResources(NodeResource entity)
		{
			this.SendPropertyChanging();
			entity.Node = this;
		}