Пример #1
0
        /// <summary>
        /// Maps domain entity to presentation
        /// </summary>
        /// <param name="player"> Domain object </param>
        /// <returns> View model object </returns>
        public static PlayerNameViewModel Map(Player player)
        {
            var playerNameViewModel = new PlayerNameViewModel {
                Id        = player.Id,
                FirstName = player.FirstName,
                LastName  = player.LastName
            };

            return(playerNameViewModel);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlayersListViewModel"/> class
        /// </summary>
        /// <param name="source">All players</param>
        /// <param name="index">Index of page</param>
        /// <param name="size">Number of players on page</param>
        /// <param name="textToSearch">Substring to search</param>
        public PlayersListViewModel(IQueryable <Player> source, int?index, int size, string textToSearch)
        {
            TextToSearch  = textToSearch;
            Size          = size;
            PageNumber    = index ?? FIRST_PAGE;
            NumberOfPages = (int)Math.Ceiling(source.Count() / (double)Size);

            if ((PageNumber > NumberOfPages) || (PageNumber < FIRST_PAGE))
            {
                throw new ArgumentOutOfRangeException();
            }

            List <PlayerViewModel> listOfPlayers = new List <PlayerViewModel>(source.Skip((PageNumber - 1) * Size)
                                                                              .Take(Size)
                                                                              .ToList()
                                                                              .Select(p => PlayerViewModel.Map(p)));

            List = new List <PlayerNameViewModel>();
            foreach (PlayerViewModel player in listOfPlayers)
            {
                List.Add(PlayerNameViewModel.Map(player));
            }
        }