Esempio n. 1
0
        public static TResult ParseContentDelegate <TResult>(string key, IFormCollection formData,
                                                             Func <string, TResult> onStringNeedsBinding,
                                                             Func <IFormFile, TResult> onFileNeedsBinding,
                                                             Func <string, TResult> onFailure)
        {
            if (formData.IsDefaultOrNull())
            {
                return(onFailure("No form data provided"));
            }

            return(formData
                   .Where(kvp => kvp.Key == key)
                   .First(
                       (kvp, next) =>
            {
                var strValue = (string)kvp.Value;
                return onStringNeedsBinding(strValue);
            },
                       () =>
            {
                return formData.Files
                .Where(file => file.Name == key)
                .First(
                    (file, next) =>
                {
                    var strValue = (IFormFile)file;
                    return onFileNeedsBinding(strValue);
                },
                    () => onFailure("Key not found"));
            }));
        }