IEnumerable <BlobViewModel> Bind(ModelBindingContext bindingContext)
        {
            var tempFileIds = GetValue(bindingContext, "TempFileId")?.Split('|').Trim().ToList();
            var filenames   = GetValue(bindingContext, "Filename")?.Split(',').Trim().ToList();
            var itemIds     = GetValue(bindingContext, "ItemId");
            var urls        = GetValue(bindingContext, "Url");
            var result      = new List <BlobViewModel>();

            if (tempFileIds?.Any() == true)
            {
                foreach (var tempFileId in tempFileIds.Select((value, index) => new { value, index }))
                {
                    var blobViewModel = new BlobViewModel
                    {
                        Action     = GetValue(bindingContext, "Action")?.To <BlobViewModelAction>() ?? BlobViewModelAction.New,
                        Filename   = filenames[tempFileId.index],
                        ItemId     = itemIds,
                        TempFileId = tempFileId.value,
                        Url        = urls,
                    };

                    blobViewModel.IsEmpty = blobViewModel.TempFileId.HasValue() ||
                                            (blobViewModel.Filename.HasValue() && blobViewModel.Filename != Blob.EMPTY_FILE);
                    result.Add(blobViewModel);
                }
            }
            return(result);
        }
Example #2
0
        BlobViewModel Bind(ModelBindingContext bindingContext)
        {
            var result = new BlobViewModel
            {
                Action     = GetValue(bindingContext, "Action")?.To <BlobViewModelAction>() ?? BlobViewModelAction.New,
                Filename   = GetValue(bindingContext, "Filename"),
                ItemId     = GetValue(bindingContext, "ItemId"),
                TempFileId = GetValue(bindingContext, "TempFileId"),
                Url        = GetValue(bindingContext, "Url")
            };

            if (result.Action == BlobViewModelAction.New && result.TempFileId.IsEmpty())
            {
                return(null);
            }

            result.IsEmpty = result.TempFileId.HasValue() ||
                             (result.Filename.HasValue() && result.Filename != Blob.EMPTY_FILE);

            return(result);
        }
Example #3
0
        protected virtual IHtmlContent DoGenerate <TModel, TProperty>(IHtmlHelper html, object viewModel, Expression <Func <TModel, TProperty> > property, object htmlAttributes)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            PropertyInfo = property.GetProperty();
            Blob         = PropertyInfo.GetValue(viewModel) as BlobViewModel ?? new BlobViewModel();

            var result = new HtmlContentBuilder();

            result.AppendHtmlLine($@"
                <div class=""file-upload"">
                    <span class=""current-file"" aria-label=""Preview the file""{" style=\"display:none\"".OnlyWhen(Blob.IsEmpty)}>
                        <a target=""_blank"" href=""{Blob.Url?.HtmlEncode()}"">{Blob.Filename.OrEmpty().HtmlEncode()}</a>
                    </span>
                    <label for={GetId("fileInput")} hidden>HiddenLabel</label>
                    {html.TextBox(PropertyInfo.Name, string.Empty, string.Empty, HiddenFieldSettings).GetString()}
                    <input type=""file"" id={GetId("fileInput")} name=""files"" {GetHtmlAttributes(htmlAttributes)}/>
                    {GetHiddenInput(x => x.Action)}
                    {GetHiddenInput(x => x.TempFileId)}
                    {GetHiddenInput(x => x.Filename)}
                    {GetHiddenInput(x => x.ItemId)}
                    {GetHiddenInput(x => x.Url)}
                    {GetHiddenInput(x => x.IsEmpty)}
                    <div class=""progress-bar"" role=""progressbar""></div>
                    <span class=""delete-file fas fa-times btn"" style=""display: none""></span>
                </div>
            ");

            return(result);
        }