Beispiel #1
0
 public override SortResult Sort(SortDto sortDto)
 {
     return(new SortResult()
     {
         Result = DoBubbleSort(sortDto.TextToSort)
     });
 }
        public void NoSpecialCharacterTest()
        {
            var sortController = new SortController();
            var sortDto        = new SortDto()
            {
                TextToSort = "Lorem Ipsu@@"
            };

            Assert.IsFalse(sortController.SortText(sortDto).IsSuccessful);
        }
Beispiel #3
0
        public async Task <IActionResult> GetAllPeopleCsv(string fields, int ascend)
        {
            SortDto sortDto = new SortDto();

            sortDto.SortAsc   = ascend;
            sortDto.SortField = fields;
            var users = await _userRepository.getUsersToCsv(sortDto);

            return(Ok(users));
        }
Beispiel #4
0
        public async Task <IActionResult> getUserWithSortingAndPagable(int take, int skip, string fields, int ascend)
        {
            SortDto sortDto = new SortDto();

            sortDto.SortAsc   = ascend;
            sortDto.SortField = fields;
            var users = await _userRepository.getUsersOnPage(take, skip, sortDto);

            return(Ok(users));
        }
Beispiel #5
0
        public void QuickSortTest()
        {
            var sortController = new SortController();
            var sortDto        = new SortDto()
            {
                SortStrategy = SortStrategy.QUICKSORT,
                TextToSort   = "simply"
            };

            Assert.AreEqual("ilmpsy", sortController.SortText(sortDto).Result);
        }
Beispiel #6
0
        public void BubbleSortTest()
        {
            var sortController = new SortController();
            var sortDto        = new SortDto()
            {
                SortStrategy = SortStrategy.BUBBLESORT,
                TextToSort   = "Lorem Ipsum"
            };

            Assert.AreEqual("ILemmoprsu", sortController.SortText(sortDto).Result);
        }
        public void InvalidOrNoSortStrategyTest()
        {
            var sortController = new SortController();
            var sortDto        = new SortDto()
            {
                TextToSort = "Lorem Ipsum"
            };

            // It should be True because not setting Sort Strategy will have default BUBBLE SORT
            Assert.IsTrue(sortController.SortText(sortDto).IsSuccessful);
        }
        public void NoNumberAllowedTest()
        {
            var sortController = new SortController();
            var sortDto        = new SortDto()
            {
                SortStrategy = SortStrategy.BUBBLESORT,
                TextToSort   = "Lorem Ipsum123"
            };

            Assert.IsFalse(sortController.SortText(sortDto).IsSuccessful);
        }
 public Boolean UpdateSortId([FromBody] SortDto sort)
 {
     try
     {
         thoughtService.UpdateSortId(sort.Id, sort.MoveToSortId);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        public virtual async Task <IActionResult> OnPostSortDateTimeAsync([FromBody] SortDto dto)
        {
            IEnumerable <TEntity> entities = await GetEntitiesToSortAsync(dto.PageId);

            var            sortOrder      = Enum.Parse <KerykeionCmsSortingOrder>(dto.SortingOrder);
            List <TEntity> sortedEntities = sortOrder switch
            {
                KerykeionCmsSortingOrder.Ascending => entities.OrderByDescending(a => a.DateTimeCreated).ToList(),
                KerykeionCmsSortingOrder.Descending => entities.OrderBy(a => a.DateTimeCreated).ToList(),
                KerykeionCmsSortingOrder.None => entities.OrderBy(a => a.DateTimeCreated).ToList(),
                _ => entities.OrderBy(a => a.DateTimeCreated).ToList(),
            };

            return(await AnonymousObjectWithSortedEntitiesAsync(sortedEntities, dto.PageId));
        }
        public virtual async Task <IActionResult> OnPostSortNameAsync([FromBody] SortDto dto)
        {
            IEnumerable <object> entities = await GetEntitiesToSortAsync(dto.Table);

            var sortOrder = Enum.Parse <KerykeionCmsSortingOrder>(dto.SortingOrder);
            List <KerykeionBaseClass> sortedEntities = sortOrder switch
            {
                KerykeionCmsSortingOrder.Ascending => entities.Cast <KerykeionBaseClass>().OrderByDescending(a => a.UniqueNameIdentifier).ToList(),
                KerykeionCmsSortingOrder.Descending => entities.Cast <KerykeionBaseClass>().OrderBy(a => a.UniqueNameIdentifier).ToList(),
                KerykeionCmsSortingOrder.None => entities.Cast <KerykeionBaseClass>().OrderBy(a => a.UniqueNameIdentifier).ToList(),
                _ => entities.Cast <KerykeionBaseClass>().OrderBy(a => a.UniqueNameIdentifier).ToList(),
            };

            return(await AnonymousObjectWithSortedEntitiesAsync(sortedEntities, dto.Table));
        }
        private void btn_doSort_Click(object sender, EventArgs e)
        {
            var sortDto = new SortDto()
            {
                TextToSort   = tb_textToSort.Text,
                SortStrategy = (SortStrategy)cb_sortingStrategy.SelectedItem
            };

            var sortResult = _sortController.SortText(sortDto);

            if (sortResult.IsSuccessful)
            {
                lbl_sorted_text.Text = sortResult.Result;
            }
            else
            {
                MessageBox.Show(sortResult.ErrorMessage);
            }
        }
 public SortResult SortText(SortDto sortDto)
 {
     if (IsTextContainsNumber(sortDto.TextToSort))
     {
         return(new SortResult("Text Contain Numbers!"));
     }
     if (string.IsNullOrEmpty(sortDto.TextToSort.ToString()))
     {
         return(new SortResult("Text To Sort Field Is Empty!"));
     }
     if (string.IsNullOrEmpty(sortDto.SortStrategy.ToString()))
     {
         return(new SortResult("No Sorting Strategy Selected!"));
     }
     if (!Regex.IsMatch(sortDto.TextToSort, @"^[a-zA-Z0-9\s.\?\,\'\;\:\!\-]+$"))
     {
         return(new SortResult("Special Character Not Allowed!"));
     }
     SetSortStrategy(sortDto.SortStrategy);
     return(_sortStrategy.Sort(sortDto));
 }
Beispiel #14
0
 /// <summary>
 /// 获取排序参数
 /// </summary>
 /// <typeparam name="TSource"></typeparam>
 /// <typeparam name="TEnum"></typeparam>
 /// <param name="sortDto"></param>
 /// <returns></returns>
 public static (bool isAsc, Expression <Func <TSource, dynamic> > keySelector) GetOrderByParam <TSource, TEnum>(this SortDto <TEnum> sortDto) where TEnum : struct, Enum
Beispiel #15
0
        public object CreateListDto(SqlDataReader reader)
        {
            Type t = typeof(T);

            if (t == typeof(BasketDto))
            {
                var BasketDto = new BasketDto()
                {
                    BasketId = (int)reader[0],
                    UserId   = (int)reader[1],
                    MatchId  = (int)reader[2],
                    EventId  = (int)reader[3]
                };
                return(BasketDto);
            }

            if (t == typeof(TeamDto))
            {
                var TeamDto = new TeamDto()
                {
                    TeamId    = (int)reader[0],
                    Name      = reader[1].ToString(),
                    SportId   = (int)reader[2],
                    Sport     = reader[3].ToString(),
                    CountryId = (int)reader[4],
                    Country   = reader[5].ToString()
                };
                return(TeamDto);
            }

            if (t == typeof(RateDto))
            {
                var RateDto = new RateDto()
                {
                    RateId   = (int)reader[0],
                    DateRate = reader.GetDateTime(1),
                    Amount   = reader.GetDecimal(2),
                    UserId   = (int)reader[3]
                };
                return(RateDto);
            }

            if (t == typeof(BetDto))
            {
                var status = new bool?();
                if (reader[2].ToString() == "")
                {
                    status = null;
                }
                else
                {
                    status = reader.GetBoolean(2);
                }
                var BetDto = new BetDto()
                {
                    BetId   = (int)reader[0],
                    MatchId = (int)reader[1],
                    Status  = status,
                    EventId = (int)reader[3],
                    //RateId= (int)reader[4]
                };
                return(BetDto);
            }

            if (t == typeof(EventDto))
            {
                var EventDto = new EventDto()
                {
                    EventId     = (int)reader[0],
                    Name        = reader[1].ToString(),
                    Coefficient = (double)reader[2],
                    MatchId     = (int)reader[3]
                };
                return(EventDto);
            }

            if (t == typeof(RoleDto))
            {
                var RoleDto = new RoleDto()
                {
                    RoleId = (int)reader[0],
                    Name   = reader[1].ToString()
                };
                return(RoleDto);
            }

            if (t == typeof(CountryDto))
            {
                var CountryDto = new CountryDto()
                {
                    CountryId = (int)reader[0],
                    Name      = reader[1].ToString()
                };
                return(CountryDto);
            }

            if (t == typeof(ResultDto))
            {
                var ResultDto = new ResultDto()
                {
                    ResultId = (int)reader[0],
                    Name     = reader[1].ToString()
                };
                return(ResultDto);
            }

            if (t == typeof(SortDto))
            {
                var SortDto = new SortDto()
                {
                    MatchId          = (int)reader[0],
                    TeamHome         = reader[1].ToString(),
                    TeamGuest        = reader[2].ToString(),
                    DateMatch        = reader.GetDateTime(3),
                    TeamHomeCountry  = reader[4].ToString(),
                    TeamGuestCountry = reader[5].ToString(),
                    Score            = reader[7].ToString(),
                    Tournament       = reader[8].ToString()
                };
                return(SortDto);
            }

            if (t == typeof(UserDto))
            {
                var UserDto = new UserDto()
                {
                    UserId      = (int)reader[0],
                    Login       = reader[1].ToString(),
                    Password    = reader[2].ToString(),
                    Email       = reader[3].ToString(),
                    Money       = reader.GetDecimal(5),
                    FIO         = reader[6].ToString(),
                    PhoneNumber = reader[7].ToString(),
                    Role        = reader[8].ToString()
                };
                return(UserDto);
            }
            if (t == typeof(MatchDto))
            {
                var MatchDto = new MatchDto()
                {
                    MatchId        = (int)reader[0],
                    TeamIdHome     = (int)reader[1],
                    TeamHome       = reader[2].ToString(),
                    TeamIdGuest    = (int)reader[3],
                    TeamGuest      = reader[4].ToString(),
                    Date           = reader.GetDateTime(5),
                    CountryHomeId  = (int)reader[6],
                    CountryHome    = reader[7].ToString(),
                    CountryGuestId = (int)reader[8],
                    CountryGuest   = reader[9].ToString(),
                    TournamentId   = (int)reader[10],
                    Tournament     = reader[11].ToString(),
                    Score          = reader[12].ToString(),
                    ResultId       = (int)reader[13],
                    Result         = reader[14].ToString(),
                    SportId        = (int)reader[15]
                };

                return(MatchDto);
            }

            if (t == typeof(BetListDto))
            {
                var BetListDto = new BetListDto()
                {
                    MatchId      = (int)reader[0],
                    CommandHome  = reader[1].ToString(),
                    CommandGuest = reader[2].ToString(),
                    Date         = reader.GetDateTime(3),
                    CountryHome  = reader.GetString(4),
                    CountryGuest = reader.GetString(5)
                };

                return(BetListDto);
            }
            else
            {
                if (t == typeof(SportDto))
                {
                    var SportDto = new SportDto()
                    {
                        SportId = (int)reader[0],
                        Name    = reader[1].ToString()
                    };

                    return(SportDto);
                }
                else
                {
                    var TournamentDto = new TournamentDto()
                    {
                        TournamentId = (int)reader[0],
                        Name         = reader[1].ToString(),
                        SportId      = (int)reader[2],
                        Sport        = reader[3].ToString()
                    };
                    return(TournamentDto);
                }
            }
        }
 public abstract SortResult Sort(SortDto sortDto);