public virtual ActionResult DeleteFile(CustomFileEntity model) { try { var db = Repository.DataContext; var entity = Repository.GetByPrimaryKey(model.ObjId); var type = TypeHelpers.GetPropertyType(entity, model.PropName); var entitySetName = TypeHelpers.GetEntitySetName(type, db); var key = new EntityKey(entitySetName, "Id", model.Id); var file = (IFileEntity)((IObjectContextAdapter)db).ObjectContext.GetObjectByKey(key); // aganzha var propValue = TypeHelpers.GetPropertyValue(entity, model.PropName); var propType = propValue.GetType(); MethodInfo methodInfo = propType.GetMethod("Remove"); object[] parametersArray = new object[] { file }; methodInfo.Invoke(propValue, parametersArray); ((IObjectContextAdapter)Repository.DataContext).ObjectContext.DeleteObject(file); //DefaultFileService.DeleteFile(file, ControllerContext.HttpContext); //var propValue = TypeHelpers.GetPropertyValue(entity, model.PropName); //if (propValue is IEnumerable) //{ // var list = ((IListSource)propValue).GetList(); // list.Remove(file); //} //else //{ // TypeHelpers.SetPropertyValue(entity, model.PropName, null); //} //((IObjectContextAdapter)db).ObjectContext.DeleteObject(file); db.SaveChanges(); return(Json(new { success = true })); } catch (Exception exception) { return(Json(new { success = false, error = exception.Message })); } }
public virtual ActionResult SaveFileData(CustomFileEntity model) { try { var db = Repository.DataContext; var entity = Repository.GetByPrimaryKey(model.ObjId); var type = TypeHelpers.GetPropertyType(entity, model.PropName); var entitySetName = TypeHelpers.GetEntitySetName(type, db); var key = new EntityKey(entitySetName, "Id", model.Id); var file = (IFileEntity)((IObjectContextAdapter)db).ObjectContext.GetObjectByKey(key); file.Alt = model.Alt; file.Description = model.Description; file.Title = model.Title; file.Visibility = model.Visibility; db.SaveChanges(); return(Json(new { success = true })); } catch (Exception exception) { return(Json(new { success = false, error = exception.Message })); } }
private void ReceiveCustomFile(LeafNodeProgress progress, String instanceName, CustomFileEntity customFile) { var downloadLink = customFile.DownloadLink; var downloadTargetPositon = Path.Combine(this.GetInstanceRootFolder(instanceName).FullName, customFile.LocalPath); Logger.GetLogger().Info(String.Format("Downloading file:{0} from remote url:{1}.", downloadTargetPositon, downloadLink)); DownloadUtils.DownloadFile(progress, downloadLink, downloadTargetPositon, customFile.Md5); Logger.GetLogger().Info(String.Format("Successfully downloaded file:{0} from remote url:{1}.", downloadTargetPositon, downloadLink)); }