private async Task <WebApiPagedResponseDto <FileInfo> > GetVideosViewModel(string physicalPath, int page = 1, int pageSize = 40, string orderColumn = nameof(FileInfo.LastWriteTime), string orderType = OrderByType.Descending) { var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken()); var repository = _fileSystemGenericRepositoryFactory.CreateFileRepository(cts.Token, physicalPath, true, "*.*", ".mp4", ".avi", ".txt"); var dataTask = repository.GetAllAsync(LamdaHelper.GetOrderByFunc <FileInfo>(orderColumn, orderType), (page - 1) * pageSize, pageSize); var totalTask = repository.GetCountAsync(null); await TaskHelper.WhenAllOrException(cts, dataTask, totalTask); var data = dataTask.Result; var total = totalTask.Result; var response = new WebApiPagedResponseDto <FileInfo> { Page = page, PageSize = pageSize, Records = total, Rows = data.ToList(), OrderColumn = orderColumn, OrderType = orderType }; return(response); }
public virtual async Task <ActionResult> Index(int page = 1, int pageSize = 10, string orderColumn = nameof(FileInfo.LastWriteTime), string orderType = "desc", string search = "") { var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken()); try { var repository = FileSystemGenericRepositoryFactory.CreateFileRepositoryReadOnly(cts.Token, PhysicalPath, IncludeSubDirectories); var dataTask = repository.SearchAsync(search, null, LamdaHelper.GetOrderByFunc <FileInfo>(orderColumn, orderType), (page - 1) * pageSize, pageSize); var totalTask = repository.GetSearchCountAsync(search, null); await TaskHelper.WhenAllOrException(cts, dataTask, totalTask); var data = dataTask.Result; var total = totalTask.Result; var rows = data.ToList().Select(Mapper.Map <FileInfo, FileMetadataDto>).ToList(); foreach (FileMetadataDto dto in rows) { dto.Id = dto.Id.Replace(PhysicalPath, ""); } var response = new WebApiPagedResponseDto <FileMetadataDto> { Page = page, PageSize = pageSize, Records = total, Rows = rows, OrderColumn = orderColumn, OrderType = orderType, Search = search }; ViewBag.Search = search; ViewBag.Page = page; ViewBag.PageSize = pageSize; ViewBag.OrderColumn = orderColumn; ViewBag.OrderType = orderType; ViewBag.DisableCreate = true; ViewBag.DisableSorting = true; ViewBag.DisableDelete = false; ViewBag.PageTitle = Title; ViewBag.Admin = Admin; return(View("List", response)); } catch { return(HandleReadException()); } }
protected async override Task <IEnumerable <SelectListItem> > GetSelectListItemsAsync(SelectListContext context) { var dataValueField = nameof(FileInfo.FullName); if (!Path.EndsWith(@"\")) { Path = Path + @"\"; } var hostingEnvironment = context.HttpContext.RequestServices.GetRequiredService <IHostingEnvironment>(); var mappedWwwPath = hostingEnvironment.MapWwwPath(Path); var mappedContentPath = hostingEnvironment.MapContentPath(Path); var searchPath = Path; var root = ""; var webFolder = false; if (mappedWwwPath != mappedContentPath) { searchPath = mappedContentPath; root = hostingEnvironment.ContentRootPath + @"\"; if (Directory.Exists(mappedWwwPath)) { webFolder = true; searchPath = mappedWwwPath; root = hostingEnvironment.WebRootPath + @"\"; } } var repository = _fileSystemGenericRepositoryFactory.CreateFileRepositoryReadOnly(default(CancellationToken), searchPath, IncludeSubDirectories, SearchPattern); var data = await repository.GetAllAsync(LamdaHelper.GetOrderByFunc <FileInfo>(OrderByProperty, OrderByType), null, null); var results = new List <SelectListItem>(); foreach (var item in data) { IHtmlHelper html = context.CreateHtmlHelper((dynamic)item); results.Add(new ModelSelectListItem() { Model = item, Html = html, Text = RemoveSearchPathFromText ? context.Eval(html, item, DataTextFieldExpression).Replace(searchPath, "") : context.Eval(html, item, DataTextFieldExpression), Value = RootRelativeValue ? webFolder ? context.Eval(html, item, dataValueField).Replace(root, "").Replace(@"\", @"/") : context.Eval(html, item, dataValueField).Replace(root, "") : context.Eval(html, item, dataValueField), }); } return(results); }
public async Task <ActionResult> Index(int page = 1, int pageSize = 20, string orderColumn = nameof(DirectoryInfo.LastWriteTime), string orderType = "desc", string search = "") { var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken()); try { var repository = _fileSystemGenericRepositoryFactory.CreateFolderRepository(cts.Token, Server.GetWwwFolderPhysicalPathById(Folders.Gallery)); var dataTask = repository.SearchAsync(search, null, LamdaHelper.GetOrderByFunc <DirectoryInfo>(orderColumn, orderType), (page - 1) * pageSize, pageSize); var totalTask = repository.GetSearchCountAsync(search, null); await TaskHelper.WhenAllOrException(cts, dataTask, totalTask); var data = dataTask.Result; var total = totalTask.Result; var response = new WebApiPagedResponseDto <DirectoryInfo> { Page = page, PageSize = pageSize, Records = total, Rows = data.ToList(), OrderColumn = orderColumn, OrderType = orderType, Search = search }; ViewBag.Search = search; ViewBag.Page = page; ViewBag.PageSize = pageSize; ViewBag.OrderColumn = orderColumn; ViewBag.OrderType = orderType; return(View(response)); } catch { return(HandleReadException()); } }
public async Task <ActionResult> Index(int page = 1, int pageSize = 100, string orderColumn = nameof(FileInfo.LastWriteTime), string orderType = "desc") { var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken()); try { var repository = _fileSystemGenericRepositoryFactory.CreateFileRepository(cts.Token, Server.GetWwwFolderPhysicalPathById(Folders.BucketList), true, "*.*", ".jpg", ".jpeg", ".txt", ".mp4", ".avi"); var dataTask = repository.GetAllAsync(LamdaHelper.GetOrderByFunc <FileInfo>(orderColumn, orderType), (page - 1) * pageSize, pageSize); var totalTask = repository.GetCountAsync(null); await TaskHelper.WhenAllOrException(cts, dataTask, totalTask); var data = dataTask.Result; var total = totalTask.Result; var response = new WebApiPagedResponseDto <FileInfo> { Page = page, PageSize = pageSize, Records = total, Rows = data.ToList(), OrderColumn = orderColumn, OrderType = orderType }; ViewBag.Page = page; ViewBag.PageSize = pageSize; ViewBag.OrderColumn = orderColumn; ViewBag.OrderType = orderType; return(View(response)); } catch { return(HandleReadException()); } }
public static IList <SelectListItem> GetSelectListFromDatabase <TDbContext>(this IHtmlHelper <dynamic> htmlHelper, string propertyName, bool selectedOnly = false) where TDbContext : DbContext { var modelExplorer = ExpressionMetadataProvider.FromStringExpression(propertyName, htmlHelper.ViewData, htmlHelper.MetadataProvider); Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata metadata = modelExplorer.Metadata; var dropdownModelType = ((Type)metadata.AdditionalValues["DropdownModelType"]); var keyProperty = ((string)metadata.AdditionalValues["KeyProperty"]); var valueProperty = ((string)metadata.AdditionalValues["DisplayExpression"]); var bindingProperty = ((string)metadata.AdditionalValues["BindingProperty"]); var orderByProperty = ((string)metadata.AdditionalValues["OrderByProperty"]); var orderByType = ((string)metadata.AdditionalValues["OrderByType"]); var physicalFilePath = ((string)metadata.AdditionalValues["PhysicalFilePath"]); var fileFolderId = ((string)metadata.AdditionalValues["FileFolderId"]); if (!string.IsNullOrEmpty(fileFolderId)) { physicalFilePath = Server.GetWwwFolderPhysicalPathById(fileFolderId); } var physicalFolderPath = ((string)metadata.AdditionalValues["PhysicalFolderPath"]); var folderFolderId = ((string)metadata.AdditionalValues["FolderFolderId"]); if (!string.IsNullOrEmpty(folderFolderId)) { physicalFolderPath = Server.GetWwwFolderPhysicalPathById(folderFolderId); } var nullable = ((bool)metadata.AdditionalValues["Nullable"]); var options = ((IEnumerable <string>)metadata.AdditionalValues["Options"]); Type propertyType = GetNonNullableModelType(metadata); List <SelectListItem> items = new List <SelectListItem>(); List <string> ids = new List <string>(); if (propertyType != typeof(string) && (propertyType.GetInterfaces().Contains(typeof(IEnumerable)))) { if (modelExplorer.Model != null) { foreach (var val in (IEnumerable)modelExplorer.Model) { if (val != null) { if (!string.IsNullOrWhiteSpace(bindingProperty)) { ids.Add(val.GetPropValue(bindingProperty).ToString()); } else { ids.Add(val.ToString()); } } } } } else { if (modelExplorer.Model != null) { if (!string.IsNullOrWhiteSpace(bindingProperty)) { ids.Add(modelExplorer.Model.GetPropValue(bindingProperty).ToString()); } else { ids.Add(modelExplorer.Model.ToString()); } } } if (!string.IsNullOrEmpty(physicalFolderPath)) { var repository = htmlHelper.FileSystemGenericRepositoryFactory().CreateFolderRepositoryReadOnly(default(CancellationToken), physicalFolderPath, true); var data = repository.GetAll(LamdaHelper.GetOrderByFunc <DirectoryInfo>(orderByProperty, orderByType), null, null); keyProperty = nameof(DirectoryInfo.FullName); data.ToList().ForEach(item => items.Add(new SelectListItem() { Text = GetDisplayString(htmlHelper, item, valueProperty).Replace(physicalFolderPath, ""), Value = item.GetPropValue(nameof(DirectoryInfo.FullName)) != null ? item.GetPropValue(nameof(DirectoryInfo.FullName)).ToString().Replace(physicalFolderPath, "") : "", Selected = item.GetPropValue(keyProperty) != null && ids.Contains(item.GetPropValue(keyProperty).ToString().Replace(physicalFolderPath, "")) })); } else if (!string.IsNullOrEmpty(physicalFilePath)) { var repository = htmlHelper.FileSystemGenericRepositoryFactory().CreateFileRepositoryReadOnly(default(CancellationToken), physicalFilePath, true); var data = repository.GetAll(LamdaHelper.GetOrderByFunc <FileInfo>(orderByProperty, orderByType), null, null); keyProperty = nameof(FileInfo.FullName); data.ToList().ForEach(item => items.Add(new SelectListItem() { Text = GetDisplayString(htmlHelper, item, valueProperty), Value = item.GetPropValue(keyProperty) != null ? item.GetPropValue(keyProperty).ToString().Replace(physicalFilePath, "") : "", Selected = item.GetPropValue(keyProperty) != null && ids.Contains(item.GetPropValue(keyProperty).ToString().Replace(physicalFilePath, "")) })); } else if (metadata.DataTypeName == "ModelRepeater") { foreach (var item in htmlHelper.ViewData.Model) { var itemObject = (Object)item; items.Add(new SelectListItem() { Text = GetDisplayString(htmlHelper, item, valueProperty), Value = itemObject.GetPropValue(keyProperty) != null ? itemObject.GetPropValue(keyProperty).ToString() : "", Selected = itemObject.GetPropValue(keyProperty) != null && ids.Contains(itemObject.GetPropValue(keyProperty).ToString()) }); } } else { //db if (options == null) { using (var db = htmlHelper.DatabaseByEntityType(dropdownModelType)) { var pi = dropdownModelType.GetProperty(orderByProperty); Type iQueryableType = typeof(IQueryable <>).MakeGenericType(new[] { dropdownModelType }); IQueryable query = db.Queryable(dropdownModelType); if (selectedOnly) { var whereClause = LamdaHelper.SearchForEntityByIds(dropdownModelType, ids.Cast <Object>()); query = (IQueryable)typeof(LamdaHelper).GetMethod(nameof(LamdaHelper.Where)).MakeGenericMethod(dropdownModelType).Invoke(null, new object[] { query, whereClause }); } else { if (metadata.AdditionalValues.ContainsKey("WhereClauseEqualsDictionary")) { var whereClauseEqualsDictionary = (Dictionary <string, List <object> >)metadata.AdditionalValues["WhereClauseEqualsDictionary"]; foreach (var where in whereClauseEqualsDictionary) { var whereClause = LamdaHelper.SearchForEntityByProperty(dropdownModelType, where.Key, where.Value); query = (IQueryable)typeof(LamdaHelper).GetMethod(nameof(LamdaHelper.Where)).MakeGenericMethod(dropdownModelType).Invoke(null, new object[] { query, whereClause }); } } if (!string.IsNullOrWhiteSpace(orderByProperty)) { if (orderByType == "asc") { query = (IQueryable)typeof(Utilities).GetMethod(nameof(Utilities.QueryableOrderBy)).MakeGenericMethod(dropdownModelType).Invoke(null, new object[] { query, orderByProperty, true }); } else { query = (IQueryable)typeof(Utilities).GetMethod(nameof(Utilities.QueryableOrderBy)).MakeGenericMethod(dropdownModelType).Invoke(null, new object[] { query, orderByProperty, false }); } } } IEnumerable results = query.ToList(dropdownModelType); foreach (var item in results) { items.Add(new SelectListItem() { Text = GetDisplayString(htmlHelper, item, valueProperty), //Value = item.GetPropValue(keyProperty) != null ? item.GetPropValue(keyProperty).ToString() : "", //Selected = item.GetPropValue(keyProperty) != null && ids.Contains(item.GetPropValue(keyProperty).ToString()) Value = GetDisplayString(htmlHelper, item, keyProperty), Selected = ids.Contains(GetDisplayString(htmlHelper, item, keyProperty)) }); } } } else { options.ToList().ForEach(item => items.Add(new SelectListItem() { Text = item, Value = item, Selected = ids.Contains(item) })); } } if (metadata.IsNullableValueType || nullable) { items.Insert(0, new SelectListItem { Text = "", Value = "" }); } return(items); }
protected async override Task <IList <SitemapNode> > GetSitemapNodes(CancellationToken cancellationToken) { IList <SitemapNode> nodes = await base.GetSitemapNodes(cancellationToken); //Locations nodes.Add( new SitemapNode() { Url = Url.AbsoluteUrl <LocationsController>(c => c.Index(1, 20, nameof(LocationDto.Name), "asc", ""), false), Priority = 0.9 }); //countries nodes.Add( new SitemapNode() { Url = Url.AbsoluteUrl <CountriesController>(c => c.Index(1, 20, nameof(LocationDto.Name), "asc", ""), false), Priority = 0.9 }); foreach (TagDto t in (await _blogService.TagApplicationService.GetAllAsync(cancellationToken, null, null, null))) { nodes.Add( new SitemapNode() { Url = Url.AbsoluteUrl(nameof(BlogController.Tag), "Blog", new { tagSlug = t.UrlSlug }), Frequency = SitemapFrequency.Weekly, Priority = 0.8 }); } foreach (CategoryDto c in (await _blogService.CategoryApplicationService.GetAsync(cancellationToken, c => c.Published, null, null))) { nodes.Add( new SitemapNode() { Url = Url.AbsoluteUrl(nameof(BlogController.Category), "Blog", new { categorySlug = c.UrlSlug }), Frequency = SitemapFrequency.Weekly, Priority = 0.8 }); } foreach (BlogPostDto p in (await _blogService.BlogPostApplicationService.GetPostsAsync(0, 200, cancellationToken))) { nodes.Add( new SitemapNode() { Url = Url.AbsoluteUrl <BlogController>(c => c.Post(p.DateCreated.Year, p.DateCreated.Month, p.UrlSlug)), Frequency = SitemapFrequency.Weekly, Priority = 0.7 }); } var repository = _fileSystemGenericRepositoryFactory.CreateFolderRepository(cancellationToken, Server.GetWwwFolderPhysicalPathById(Folders.Gallery)); foreach (DirectoryInfo f in (await repository.GetAllAsync(LamdaHelper.GetOrderByFunc <DirectoryInfo>(nameof(DirectoryInfo.LastWriteTime), OrderByType.Descending), null, null))) { nodes.Add( new SitemapNode() { Url = Url.AbsoluteUrl("Gallery", "Gallery", new { name = f.Name.ToSlug() }), Frequency = SitemapFrequency.Weekly, Priority = 0.7 }); } foreach (LocationDto l in (await _locationService.GetAllAsync(cancellationToken, null, null, null))) { if (!string.IsNullOrEmpty(l.UrlSlug)) { nodes.Add( new SitemapNode() { Url = Url.AbsoluteUrl <LocationsController>(lc => lc.Location(l.UrlSlug)), Frequency = SitemapFrequency.Weekly, Priority = 0.6 }); } } return(nodes); }