Esempio n. 1
0
        public TeamViewModel(Team team, IChangeManager changeManager, CollectionFactory collections)
        {
            _changeManager = changeManager;

            Collections = collections;

            Id      = team.Id;
            Name    = team.Name;
            Manager = Collections.ManagerViewModels.Find(m => m.Id == team.ManagerId);
            Captain = team.Squad.Exists(p => p.IsCaptain) ? new SoccerPlayerViewModel(team.Squad.Find(p => p.IsCaptain), Collections, _changeManager) : new SoccerPlayerViewModel();
            Nation  = Collections.NationViewModels.Find(n => n.Id == team.NationId);
            City    = Collections.CityViewModels.Find(c => c.Id == team.CityId);
            Sport   = Collections.SportViewModels.Find(s => s.Id == team.SportId);
            Crest   = new EditableCellViewModel(team.CrestImagePath, _changeManager);
            Squad   = team.Squad.Count > 0 ? team.Squad.Select(p => new SoccerPlayerViewModel(p, Collections, _changeManager)).ToList() : new List <SoccerPlayerViewModel>();
        }
Esempio n. 2
0
        public SoccerPlayerViewModel(SoccerPlayer model = null, CollectionFactory collections = null, IChangeManager changeManager = null)
        {
            if (model == null)
            {
                return;
            }
            Id           = model.Id;
            TeamId       = model.TeamId;
            Name         = new EditableCellViewModel(model.Name, changeManager, ColumnName.PlayerName, model);
            Age          = new CellViewModel(model.Age);
            BirthDate    = new EditableCellViewModel(model.BirthDate.ToShortDateString(), changeManager, ColumnName.BirthDate, model);
            IsCaptain    = new EditableCellViewModel(model.IsCaptain, changeManager, ColumnName.IsCaptain, model);
            Position     = new ComboBoxCellViewModel(collections.PositionRoles.Find(pr => pr == model.Position.Role), collections.PositionRoles, changeManager, model, ColumnName.Position);
            Group        = model.Position.Group;
            Rating       = new EditableCellViewModel(model.Rating, changeManager, ColumnName.Rating, model);
            Nationality  = new ComboBoxCellViewModel(collections.NationViewModels.Find(n => n.Id == model.Nationality), collections.NationViewModels, changeManager, model, ColumnName.Nationality);
            RotationTeam = new CellViewModel(model.Rotation);
            IsLineup     = model.IsLineup;
            IsNewPlayer  = new CellViewModel(false);

            IsEnabled = true;
        }
Esempio n. 3
0
        public SoccerPlayerViewModel(SoccerPlayerViewModel viewModel, CollectionFactory collections, IChangeManager changeManager)
        {
            if (viewModel == null)
            {
                return;
            }
            var playerModel = new SoccerPlayer(viewModel);

            Id     = viewModel.Id;
            TeamId = viewModel.TeamId;
            Name   = new EditableCellViewModel(viewModel.Name.Value, changeManager, ColumnName.PlayerName, playerModel);

            DateTime birthDate = new DateTime();

            if (viewModel.BirthDate.Value is DateTime)
            {
                birthDate = (DateTime)viewModel.BirthDate.Value;
            }
            else
            {
                birthDate = DateTime.Parse((string)viewModel.BirthDate.Value);
            }
            BirthDate = new EditableCellViewModel(birthDate.ToShortDateString(), changeManager, ColumnName.BirthDate, playerModel);

            Age          = new CellViewModel(DateTime.Now.Year - birthDate.Year);
            IsCaptain    = new EditableCellViewModel(viewModel.IsCaptain.Value, changeManager, ColumnName.IsCaptain, playerModel);
            Position     = new ComboBoxCellViewModel(collections.PositionRoles.Find(pr => pr == (PositionRole)viewModel.Position.Value), collections.PositionRoles, changeManager, playerModel, ColumnName.Position);
            Group        = viewModel.Group;
            Nationality  = new ComboBoxCellViewModel(collections.NationViewModels.Find(n => n.Id == (viewModel.Nationality.Value as ComboBoxItemViewModel).Id), collections.NationViewModels, changeManager, playerModel, ColumnName.Nationality);
            Rating       = new EditableCellViewModel(viewModel.Rating.Value, changeManager, ColumnName.Rating, playerModel);
            RotationTeam = new CellViewModel(viewModel.RotationTeam.Value);
            IsNewPlayer  = new CellViewModel(false);
            IsLineup     = viewModel.IsLineup;

            IsEnabled = true;
        }