Beispiel #1
0
        /// <summary>
        /// Return image which related by user(upload/vote).
        /// </summary>
        public async Task <IActionResult> PreviewUserImage(int id)
        {
            if (!this.Request.Cookies.TryGetValue("imageRelateByUserData", out string readPagingDataCookie))
            {
                return(this.BadRequest());
            }

            var options = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true,
            };
            ImagePagingCookieData cookieSearchData = JsonSerializer.Deserialize <ImagePagingCookieData>(readPagingDataCookie, options);

            ApplicationUser userPreviewProfil = await this.userManager.FindByIdAsync(cookieSearchData.UserId);

            if (userPreviewProfil == null)
            {
                return(this.BadRequest());
            }

            SearchImageData localSearchData = null;

            if (cookieSearchData.Type == "uploads")
            {
                localSearchData = new SearchImageData
                {
                    AuthorId = userPreviewProfil.Id,
                };
            }
            else if (cookieSearchData.Type == "likes")
            {
                localSearchData = new SearchImageData
                {
                    LikeByUser = userPreviewProfil.Id,
                };
            }

            if (this.User.Identity.IsAuthenticated)
            {
                ApplicationUser loginUser = await this.userManager.GetUserAsync(this.User);

                localSearchData.LikeForUserId = loginUser.Id;
            }

            var data = this.imagesService.GetByFilter <ImagePreviewViewModel>(
                localSearchData, 1, id);

            if (!data.Any())
            {
                return(this.Json(string.Empty));
            }
            else
            {
                ImagePreviewViewModel previewImage = data.First();
                previewImage.ImageIndex = id;

                return(this.PartialView("_PreviewImagePartial", previewImage));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> PreviewImage(int id)
        {
            if (!this.Request.Cookies.TryGetValue("searchData", out string readSearchDataCookie))
            {
                return(this.BadRequest());
            }

            var options = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true,
            };
            SeachCookieData cookieSearchData = JsonSerializer.Deserialize <SeachCookieData>(readSearchDataCookie, options);

            SearchImageData localSearchData = new SearchImageData
            {
                FilterByTag    = cookieSearchData.SearchText,
                FilterCategory = cookieSearchData.SelectCategory,
            };

            if (this.User.Identity.IsAuthenticated)
            {
                ApplicationUser user = await this.userManager.GetUserAsync(this.User);

                localSearchData.LikeForUserId = user.Id;
            }

            var data = this.imagesService.GetByFilter <ImagePreviewViewModel>(
                localSearchData, 1, id);

            if (!data.Any())
            {
                return(this.Json(string.Empty));
            }
            else
            {
                ImagePreviewViewModel previewImage = data.First();
                previewImage.ImageIndex = id;

                return(this.PartialView("_PreviewImagePartial", previewImage));
            }
        }
Beispiel #3
0
 public ImagePreview(ImagePreviewViewModel model)
 {
     ViewModel = model;
     InitializeComponent();
 }
        public void Update_Will_Be_Ok()
        {
            var model = new ImagePreviewViewModel()
            {
                Id = 1,
                ImageDescription = "asdfasdf",
                ImagePath = "asdf.asdf"
            };

            this.controller.WithCallTo(x => x.Update(model))
                .ShouldRenderPartialView("_ItemPartial");
        }
Beispiel #5
0
        public ImagePreviewPage(ImagePreviewViewModel viewModel)
        {
            InitializeComponent();

            DataContext = viewModel;
        }
        public ActionResult Update(ImagePreviewViewModel model)
        {
            if (model == null || !this.ModelState.IsValid)
            {
                return this.PartialView("_Error", new ErrorViewModel() { Message = ModelConstants.ModelError });
            }

            var image = this.imageService.GetById(model.Id);

            if (image == null)
            {
                return this.PartialView("_Error", new ErrorViewModel() { Message = ModelConstants.FileNotFound });
            }

            var imageToUpdate = this.Mapper.Map<Image>(model);
            this.imageService.Update(imageToUpdate);

            var updatedImage = this.Mapper.Map<ImagePreviewViewModel>(imageToUpdate);
            return this.PartialView("_ItemPartial", updatedImage);
        }
        public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, string path, IList <ListedItem> filesAndFolders)
        {
            IUserSettingsService userSettingsService = Ioc.Default.GetService <IUserSettingsService>();

            if (userSettingsService.PreferencesSettingsService.AreLayoutPreferencesPerFolder &&
                folderSettings.IsAdaptiveLayoutEnabled &&
                !folderSettings.IsLayoutModeFixed)
            {
                Action layoutDetails  = () => folderSettings.ToggleLayoutModeDetailsView(false);
                Action layoutTiles    = () => folderSettings.ToggleLayoutModeTiles(false);
                Action layoutGridView = () => folderSettings.ToggleLayoutModeGridView(folderSettings.GridViewSize);

                bool desktopIniFound = false;

                if (string.IsNullOrWhiteSpace(path))
                {
                    return(false);
                }

                var iniPath     = System.IO.Path.Combine(path, "desktop.ini");
                var iniContents = NativeFileOperationsHelper.ReadStringFromFile(iniPath)?.Trim();
                if (!string.IsNullOrEmpty(iniContents))
                {
                    var parser = new IniParser.Parser.IniDataParser();
                    parser.Configuration.ThrowExceptionsOnError = false;
                    var data = parser.Parse(iniContents);
                    if (data != null)
                    {
                        var viewModeSection = data.Sections.FirstOrDefault(x => "ViewState".Equals(x.SectionName, StringComparison.OrdinalIgnoreCase));
                        if (viewModeSection != null)
                        {
                            var folderTypeKey = viewModeSection.Keys.FirstOrDefault(s => "FolderType".Equals(s.KeyName, StringComparison.OrdinalIgnoreCase));
                            if (folderTypeKey != null)
                            {
                                var setLayout = (folderTypeKey.Value) switch
                                {
                                    "Documents" => layoutDetails,
                                    "Pictures" => layoutGridView,
                                    "Music" => layoutDetails,
                                    "Videos" => layoutGridView,
                                    _ => layoutDetails
                                };
                                setLayout();
                                desktopIniFound = true;
                            }
                        }
                    }
                }

                if (desktopIniFound)
                {
                    return(true);
                }
                if (filesAndFolders.Count == 0)
                {
                    return(false);
                }

                int allItemsCount = filesAndFolders.Count;

                int mediaCount;
                int imagesCount;
                int foldersCount;
                int miscFilesCount;

                float mediaPercentage;
                float imagesPercentage;
                float foldersPercentage;
                float miscFilesPercentage;

                mediaCount = filesAndFolders.Where((item) =>
                {
                    return(!string.IsNullOrEmpty(item.FileExtension) && MediaPreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant()));
                }).Count();
                imagesCount = filesAndFolders.Where((item) =>
                {
                    return(!string.IsNullOrEmpty(item.FileExtension) && ImagePreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant()));
                }).Count();
                foldersCount   = filesAndFolders.Where((item) => item.PrimaryItemAttribute == StorageItemTypes.Folder).Count();
                miscFilesCount = allItemsCount - (mediaCount + imagesCount + foldersCount);

                mediaPercentage     = (float)((float)mediaCount / (float)allItemsCount) * 100.0f;
                imagesPercentage    = (float)((float)imagesCount / (float)allItemsCount) * 100.0f;
                foldersPercentage   = (float)((float)foldersCount / (float)allItemsCount) * 100.0f;
                miscFilesPercentage = (float)((float)miscFilesCount / (float)allItemsCount) * 100.0f;

                // Decide layout mode

                // Mostly files + folders, lesser media and image files | Mostly folders
                if ((foldersPercentage + miscFilesPercentage) > Constants.AdaptiveLayout.LargeThreshold)
                {
                    layoutDetails();
                }
                // Mostly images, probably an images folder
                else if (imagesPercentage > Constants.AdaptiveLayout.ExtraLargeThreshold ||
                         (imagesPercentage > Constants.AdaptiveLayout.MediumThreshold &&
                          (mediaPercentage + miscFilesPercentage + foldersPercentage) > Constants.AdaptiveLayout.SmallThreshold &&
                          (miscFilesPercentage + foldersPercentage) < Constants.AdaptiveLayout.ExtraSmallThreshold))
                {
                    layoutGridView();
                }
                // Mostly media i.e. sound files, videos
                else if (mediaPercentage > Constants.AdaptiveLayout.ExtraLargeThreshold ||
                         (mediaPercentage > Constants.AdaptiveLayout.MediumThreshold &&
                          (imagesPercentage + miscFilesPercentage + foldersPercentage) > Constants.AdaptiveLayout.SmallThreshold &&
                          (miscFilesPercentage + foldersPercentage) < Constants.AdaptiveLayout.ExtraSmallThreshold))
                {
                    layoutDetails();
                }
                else
                {
                    layoutDetails();
                }

                return(true);
            }

            return(false);
        }
    }