//this function sorts parsed records
 public static List <RecordDto> SortRecords(List <RecordDto> recordsDto, Enums.SortType sortType)
 {
     try
     {
         List <RecordDto> sortedRecords = null;
         if (sortType.Equals(Enums.SortType.GenderAndLastNameAsc))
         {
             sortedRecords = recordsDto.OrderBy(i => i.Gender).ThenBy(i => i.LastName).ToList();
         }
         else if (sortType.Equals(Enums.SortType.BirthDateAsc))
         {
             sortedRecords = recordsDto.OrderBy(i => Convert.ToDateTime(i.DateOfBirth)).ToList();
         }
         else if (sortType.Equals(Enums.SortType.LastNameDesc))
         {
             sortedRecords = recordsDto.OrderByDescending(i => i.LastName).ToList();
         }
         return(sortedRecords);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error while executing SortRecords");
         throw ex;
     }
 }
Beispiel #2
0
 public PageInfo()
 {
     IsSelectTop      = false;
     IsPage           = true;
     CurrentPageIndex = 0;
     PageSize         = 10;
     RecordCount      = 0;
     SortField1       = null;
     SortType1        = Enums.SortType.ASC;
     SortField2       = null;
     SortType2        = Enums.SortType.ASC;
     SortField3       = null;
     SortType3        = Enums.SortType.ASC;
 }
Beispiel #3
0
        private void listViewFilePick_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            if ((int)this.sortColumn == e.Column)
            {
                this.sortType = (this.sortType == Enums.SortType.Ascending) ? Enums.SortType.Descending : Enums.SortType.Ascending;
            }
            else
            {
                this.sortColumn = (Enums.SortColumn)e.Column;
                this.sortType   = Enums.SortType.Ascending;
            }

            this.LoadFiles(this.fullPath, this.sortColumn, this.sortType);
        }
 public static string GetSortOrderDescription(Enums.SortType sortType)
 {
     if (sortType.Equals(Enums.SortType.GenderAndLastNameAsc))
     {
         return("gender (females before males) then by last name ascending");
     }
     else if (sortType.Equals(Enums.SortType.BirthDateAsc))
     {
         return("birth date, ascending");
     }
     else if (sortType.Equals(Enums.SortType.LastNameDesc))
     {
         return("last name, descending");
     }
     return(string.Empty);
 }
Beispiel #5
0
        /// <summary>
        /// Load into the ListView the files that belongs to the path received
        /// A empty path string means MiComputer (default location)
        /// </summary>
        /// <param name="path">Path to load into the listview</param>
        /// <param name="column">Sorting column of the items to load into the listview</param>
        /// <param name="type">Sort order of items to load into the listview</param>
        private void LoadFiles(string path, Enums.SortColumn column, Enums.SortType type)
        {
            try
            {
                this.lblFoundFiles.Visible = false;

                List <ListViewItem> listViewItems = ListViewHelper.GetItemsAtPath(path, column, type);

                // add list to ListView control
                this.listViewFilePick.Items.Clear();
                this.listViewFilePick.Items.AddRange(listViewItems.ToArray());

                this.lblFoundFiles.Text    = listViewItems.Count.ToString() + " files found";
                this.lblFoundFiles.Visible = true;
            }
            catch (Exception) { }
        }
Beispiel #6
0
        //This function displays parsed records on user console
        private static void DisplayRecords(List <RecordDto> recordsDto, Enums.SortType sortType)
        {
            List <RecordDto> sortedRecords = BusinessLogic.SortRecords(recordsDto, sortType);

            try
            {
                if (sortedRecords != null)
                {
                    string sortOrderString = Utility.GetSortOrderDescription(sortType);
                    Console.WriteLine(string.Format("\nDisplaying records sorted by {0}", sortOrderString));

                    foreach (var recordDto in sortedRecords)
                    {
                        Console.WriteLine(string.Format("{0} {1} {2} {3} {4}", recordDto.LastName, recordDto.FirstName, recordDto.Gender, recordDto.FavoriteColor, recordDto.DateOfBirth));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while executing Displayrecord");
                throw ex;
            }
        }
        public async Task <MaterialsCollectionViewModel> GetMaterials(
            string searchText           = null, Enums.Auditory auditory = Enums.Auditory.Common,
            Enums.Theme theme           = Enums.Theme.Common,
            Enums.Type type             = Enums.Type.Common,
            Enums.MaterialStatus status = Enums.MaterialStatus.All, int page = 0,
            Guid?userId = null, Enums.SortType sortType = Enums.SortType.AlphabetAsc,
            int count   = 3)
        {
            var materials = await _unitOfWork.MaterialRepository.GetAll();

            materials = materials.ToList();

            if (status != Enums.MaterialStatus.All)
            {
                materials = materials.Where(m => m.Status == status).ToList();
            }

            if (auditory != Enums.Auditory.Common)
            {
                materials = materials.Where(m => m.Auditory == auditory).ToList();
            }

            if (type != Enums.Type.Common)
            {
                materials = materials.Where(m => m.Type == type).ToList();
            }

            if (theme != Enums.Theme.Common)
            {
                materials = materials.Where(m => m.Theme == theme).ToList();
            }

            if (!string.IsNullOrEmpty(searchText))
            {
                materials = materials.Where(m =>
                                            m.Name.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0 ||
                                            m.Description.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0 ||
                                            m.Theme.ToString("d").IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0);
            }

            if (userId != null)
            {
                materials = materials.Where(m => m.UserId == userId).ToList();
            }

            if (sortType == Enums.SortType.AlphabetAsc)
            {
                materials = materials.OrderBy(m => m.Name).ToList();
            }
            else if (sortType == Enums.SortType.AlphabetDesc)
            {
                materials = materials.OrderByDescending(m => m.Name).ToList();
            }
            else if (sortType == Enums.SortType.DateAsc)
            {
                materials = materials.OrderBy(m => m.PublishingDate).ToList();
            }
            else if (sortType == Enums.SortType.DateDesc)
            {
                materials = materials.OrderByDescending(m => m.PublishingDate).ToList();
            }
            else if (sortType == Enums.SortType.RateAsc)
            {
                materials = materials.OrderByDescending(m => m.Rating).ToList();
            }

            var materialsCount = materials.Count();

            if (page != 0)
            {
                materials = materials.Skip(0).Take(count * page);
            }

            var uiMaterials = materials.Select(m => new MaterialViewModel
            {
                Id                   = m.Id,
                Name                 = m.Name,
                UserId               = m.UserId,
                AuthorEmail          = _unitOfWork.UserRepository.GetUserById(m.UserId).Email,
                AuthorName           = _unitOfWork.UserRepository.GetUserById(m.UserId).Name,
                AuthorSurname        = _unitOfWork.UserRepository.GetUserById(m.UserId).Surname,
                Description          = m.Description,
                PublishingDate       = m.PublishingDate,
                PublishingDateString = m.PublishingDate.ToString("dd.MM.yyyy"),
                Status               = m.Status,
                StatusString         = Constants.Status[(int)m.Status],
                Auditory             = m.Auditory,
                Theme                = m.Theme,
                ThemeString          = Constants.Theme[(int)m.Theme],
                Type                 = m.Type,
                TypeString           = Constants.Type[(int)m.Type],
                DownloadingLink      = m.DownloadingLink,
                BytePicture          = m.Picture,
                Base64Picture        = Convert.ToBase64String(m.Picture),
                SourceOfInformation  = m.SourceOfInformation,
                Rating               = m.Rating,
                DownloadsCount       = m.DownloadsCount
            });

            return(new MaterialsCollectionViewModel
            {
                SearchText = searchText,
                Type = type,
                Theme = theme,
                ThemeString = Constants.Theme[(int)theme],
                Materials = uiMaterials,
                Page = page,
                TotalCount = materialsCount
            });
        }
Beispiel #8
0
        public static async Task <Classes.Response.WallpapersList> GetWallpapersByCategory(int categoryID, Enums.SortType sort)
        {
            try
            {
                var getWallpapersByCategory = await client.GetAsync(Helpers.UriCreator.GetWallpapersByCategory(Setting.Instance.APIKey, categoryID, sort: sort, width: Setting.Instance.Width, height: Setting.Instance.Height, @operator: Setting.Instance.Operator));

                if (getWallpapersByCategory.IsSuccessStatusCode)
                {
                    string responseBody = await getWallpapersByCategory.Content.ReadAsStringAsync();

                    var json = JsonConvert.DeserializeObject <Classes.Response.WallpapersList>(responseBody);

                    return(json);
                }
                else
                {
                    return(new Classes.Response.WallpapersList
                    {
                        Success = false,
                        Error = $"Bad status code: {getWallpapersByCategory.StatusCode}"
                    });
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error getting wallpaper with specific cateogry with API, message: " + ex.Message);
                return(new Classes.Response.WallpapersList
                {
                    Success = false,
                    Error = "Error getting wallpaper with specific cateogry with API, message: " + ex.Message,
                });
            }
        }
Beispiel #9
0
        /// <summary>
        /// Returns a sorted List<ListViewItem> with the files of received path.
        /// </summary>
        public static List <ListViewItem> GetItemsAtPath(string path, Enums.SortColumn column, Enums.SortType type)
        {
            var listViewItems = new List <ListViewItem>();
            var filesInfo     = new FileInfo[0];

            try
            {
                filesInfo = new DirectoryInfo(path).GetFiles();
            }
            catch { }

            foreach (var fileInfo in filesInfo)
            {
                var listViewItem = new ListViewItem
                {
                    Text       = fileInfo.Name,
                    ImageIndex = Constants.IMG_INDEX_FILE
                };
                listViewItem.SubItems.Add(Math.Ceiling((double)fileInfo.Length / 1024).ToString() + " KB");

                listViewItems.Add(listViewItem);
            }

            // custom sort
            listViewItems.Sort(new ColumnComparer(column, type));

            return(listViewItems);
        }
        public static Uri GetWallpapersByCategory(string apiKey, int categoryID, int page = 1, int infoLevel = 1, Enums.SortType sort = Enums.SortType.Newest, int width = 0, int height = 0, Enums.OperatorType @operator = Enums.OperatorType.Equal, int checkLast = 0)
        {
            if (!Uri.TryCreate(Wallalphacoders, string.Format(Constant.GET_WALLPAPERS_BY_CATEGORY, apiKey, categoryID, page, infoLevel, sort.ToString().ToLower(), width, height, "", checkLast), out var uri))
            {
                throw new Exception("Cant create URI for categories list");
            }

            return(uri);
        }
 public ColumnComparer(Enums.SortColumn sortColumn, Enums.SortType sortType)
 {
     this.sortColumn = sortColumn;
     this.sortType   = sortType;
 }