public Task BindModelAsync(ModelBindingContext bindingContext) { if (bindingContext == null) { throw new ArgumentNullException(nameof(bindingContext)); } var defaultBindingContext = bindingContext as DefaultModelBindingContext; var composite = bindingContext.ValueProvider as CompositeValueProvider; if (defaultBindingContext != null && composite != null && !composite.Any()) { bindingContext.ValueProvider = defaultBindingContext.OriginalValueProvider; } var result = new UploadModel(); if (bindingContext.GetBoolValue(nameof(result.CreateNewIfExist), out var createNewIfExist)) { result.CreateNewIfExist = createNewIfExist; } if (bindingContext.GetBoolValue(nameof(result.KeepConvertStatus), out var keepConvertStatus)) { result.KeepConvertStatus = keepConvertStatus; } if (bindingContext.GetBoolValue(nameof(result.StoreOriginalFileFlag), out var storeOriginalFileFlag)) { result.StoreOriginalFileFlag = storeOriginalFileFlag; } if (bindingContext.GetFirstValue(nameof(result.ContentType), out var contentType)) { if (!string.IsNullOrEmpty(contentType)) { result.ContentType = new ContentType(contentType); } } if (bindingContext.GetFirstValue(nameof(result.ContentDisposition), out var contentDisposition)) { if (!string.IsNullOrEmpty(contentDisposition)) { result.ContentDisposition = new ContentDisposition(contentDisposition); } } bindingContext.HttpContext.Request.EnableBuffering(); bindingContext.HttpContext.Request.Body.Position = 0; result.Stream = new MemoryStream(); bindingContext.HttpContext.Request.Body.CopyToAsync(result.Stream).Wait(); result.Stream.Position = 0; bindingContext.Result = ModelBindingResult.Success(result); return(Task.CompletedTask); }
public override Task BindModelAsync(ModelBindingContext bindingContext) { base.BindModelAsync(bindingContext); if (bindingContext == null) { throw new ArgumentNullException(nameof(bindingContext)); } var result = new BatchModel(); var baseResult = bindingContext.Result.Model as BaseBatchModel; if (baseResult == null) { bindingContext.Result = ModelBindingResult.Success(result); return(Task.CompletedTask); } result.FileIds = baseResult.FileIds; result.FolderIds = baseResult.FolderIds; if (bindingContext.GetBoolValue(nameof(result.DeleteAfter), out var deleteAfter)) { result.DeleteAfter = deleteAfter; } if (bindingContext.GetFirstValue(nameof(result.ConflictResolveType), out var сonflictResolveTypeValue)) { if (Enum.TryParse <FileConflictResolveType>(сonflictResolveTypeValue, out var conflictResolveType)) { result.ConflictResolveType = conflictResolveType; } } if (bindingContext.GetFirstValue(nameof(result.DestFolderId), out var firstValue)) { result.DestFolderId = ModelBindingContextExtension.ParseQueryParam(firstValue); } bindingContext.Result = ModelBindingResult.Success(result); return(Task.CompletedTask); }