Exemplo n.º 1
0
        public void TestHandleSave_NonForcedNameChanged()
        {
            // Arrange
            Utils.PlayerDummy player = new Utils.PlayerDummy();
            DummyTeam         team   = new DummyTeam();

            team.Name = "Test Team #1";
            team.List.Add(player);
            TeamVM teamVM = new TeamVM {
                Model = team
            };

            templatesController.ViewModel.ViewModels.Add(teamVM);

            DummyTeam team2        = team.Clone();
            string    expectedName = "Test Team #2";

            team2.Name = expectedName;

            // Action
            App.Current.EventsBroker.Publish(new UpdateEvent <Team> ()
            {
                Object = team2,
                Force  = false
            });

            // Assert
            mockDialogs.Verify(m => m.QuestionMessage(It.IsAny <string> (), null, It.IsAny <DummyTemplatesController> ()), Times.Once());
            Assert.AreEqual(templatesController.ViewModel.ViewModels.First(x => x.ID == team.ID).Name,
                            expectedName);
            Assert.IsFalse(templatesController.ViewModel.SaveCommand.CanExecute());
        }
Exemplo n.º 2
0
        public IActionResult CreateTeam(TeamVM newTeam)
        {
            if (!ModelState.IsValid)
            {
                throw new Exception("Model invalid");
            }
            int userId = 0;

            if (Int32.TryParse(HttpContext.Session.GetString("UserId"), out userId))
            {
                var request = new CreateTeamRequest
                {
                    Team = new Team
                    {
                        TeamName = newTeam.TeamName
                    },
                    UserId = userId
                };
                var response = service.CreateTeam(request);

                if (response.Success)
                {
                    return(RedirectToAction("UserDashboard"));
                }

                ViewBag.Error = response.ErrorMessage;
            }

            return(View());
        }
Exemplo n.º 3
0
        public void Search_TemplateExist_TemplateFound()
        {
            //Arrange
            Utils.PlayerDummy player = new Utils.PlayerDummy();
            DummyTeam         team   = new DummyTeam {
                Name = "Dummy"
            };

            team.List.Add(player);
            TeamVM teamVM = new TeamVM {
                Model = team
            };

            templatesController.ViewModel.ViewModels.Add(teamVM);

            //Act
            var evt = new SearchEvent {
                TextFilter = "Dummy"
            };

            // Action
            App.Current.EventsBroker.Publish(evt);


            //Assert
            Assert.AreEqual(1, templatesController.ViewModel.VisibleViewModels.Count);
            Assert.AreEqual("Dummy", templatesController.ViewModel.VisibleViewModels.FirstOrDefault().Name);
        }
Exemplo n.º 4
0
        public void TestHandleSave_ForcedNameChanged()
        {
            // Arrange
            Utils.PlayerDummy player = new Utils.PlayerDummy();
            DummyTeam         team   = new DummyTeam();

            team.Name = "Test Team #1";
            team.List.Add(player);
            TeamVM teamVM = new TeamVM {
                Model = team
            };

            templatesController.ViewModel.ViewModels.Add(teamVM);

            DummyTeam team2        = team.Clone();
            string    expectedName = "Test Team #2";

            team2.Name = expectedName;

            // Action
            App.Current.EventsBroker.Publish(new UpdateEvent <Team> ()
            {
                Object = team2,
                Force  = true
            });

            // Assert
            Assert.AreEqual(templatesController.ViewModel.ViewModels.First(x => x.ID == team.ID).Name,
                            expectedName);
            Assert.IsFalse(templatesController.ViewModel.SaveCommand.CanExecute());
        }
Exemplo n.º 5
0
        public IActionResult TeamDashboard(int teamId)
        {
            if (HttpContext.Session.GetString("UserId") != null)
            {
                ViewBag.UserName = HttpContext.Session.GetString("UserName");

                var request = new GetTeamByIdRequest {
                    TeamId = teamId
                };
                var response = service.GetTeamById(request);
                var team     = new TeamVM
                {
                    TeamId   = teamId,
                    TeamName = response.Team.TeamName
                };

                var teamMembers = new List <TeamMemberVm>();
                foreach (var member in response.Members)
                {
                    teamMembers.Add(new TeamMemberVm
                    {
                        UserId   = member.UserId,
                        UserName = member.UserName,
                        UserRole = member.UserRole
                    });
                }

                team.TeamMembers = teamMembers;

                return(View(team));
            }
            return(RedirectToAction("Login"));
        }
Exemplo n.º 6
0
        public void Search_TemplateThatDoesntExist_VisibleViewModelsEmpty()
        {
            //Arrange
            Utils.PlayerDummy player = new Utils.PlayerDummy();
            DummyTeam         team   = new DummyTeam {
                Name = "Dummy"
            };

            team.List.Add(player);
            TeamVM teamVM = new TeamVM {
                Model = team
            };

            templatesController.ViewModel.ViewModels.Add(teamVM);

            //Act
            var evt = new SearchEvent {
                TextFilter = "This doesn't exist"
            };

            // Action
            App.Current.EventsBroker.Publish(evt);


            //Assert
            Assert.AreEqual(0, templatesController.ViewModel.VisibleViewModels.Count);
        }
Exemplo n.º 7
0
        public ActionResult Team(int id)
        {
            var team = Context.EventTeams.GetById(id);
            var vm   = new TeamVM
            {
                Name  = team.Name,
                Users = team.Users.Select(u => new UserVM
                {
                    FirstName    = u.FirstName,
                    Id           = u.Id,
                    LastName     = u.LastName,
                    UserName     = u.UserName,
                    SkillRatings = u.UserSkills.Select(us => new SkillRatingVM
                    {
                        Rating = us.Ratings.Average(r => r.Mark),
                        Name   = us.Skill.Name
                    })
                }),
                //SkillNames = team.Event.Skills.Select(s => s.Name) TODO: Only get skills from event not all in users
            };

            vm.SkillNames = vm.Users.First().SkillRatings.Select(x => x.Name).ToList();

            return(View(vm));
        }
Exemplo n.º 8
0
        public ActionResult MenuHeader()
        {
            var vm = new UserMenuHeaderVM();

            try
            {
                var user = repo.GetUser(UserID);
                if (user != null)
                {
                    vm.UserDisplayName = user.FirstName;
                    vm.UserAvatarHash  = UserService.GetAvatarUrl(user.Avatar);
                    var teams = repo.GetTeams(UserID).ToList();
                    foreach (var team in teams)
                    {
                        var teamVM = new TeamVM {
                            Id = team.ID, Name = team.Name
                        };
                        vm.Teams.Add(teamVM);
                        if (team.ID == TeamID)
                        {
                            vm.CurrentTeamName = team.Name;
                        }
                    }
                    vm.SelectedTeam = TeamID;
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            return(PartialView("Partial/MenuHeader", vm));
        }
Exemplo n.º 9
0
        public IHttpActionResult JoinTeam(TeamVM objTeamInfo)
        {
            StringBuilder          traceLog    = null;
            ServiceResponse <bool> objResponse = null;

            try
            {
                traceLog = new StringBuilder();
                traceLog.AppendLine("Start: JoinTeam() Request Data:-TrainerId-" + objTeamInfo.TeamId);
                objResponse              = new ServiceResponse <bool>();
                objResponse.jsonData     = TeamBL.JoinTeam(objTeamInfo);
                objResponse.IsResultTrue = true;
                return(Ok(objResponse));
            }
            catch (Exception ex)
            {
                LogManager.LogManagerInstance.WriteErrorLog(ex);
                return(BadRequest(ex.Message));
            }
            finally
            {
                traceLog.AppendLine("End:JoinTeam() Response Data-" + objResponse.IsResultTrue + ",Joined Datetime" + DateTime.Now.ToLongDateString());
                LogManager.LogManagerInstance.WriteTraceLog(traceLog);
                traceLog = null;
            }
        }
Exemplo n.º 10
0
        public void TestHandleSave_SaveStatic()
        {
            // Arrange
            Utils.PlayerDummy player = new Utils.PlayerDummy();
            DummyTeam         team   = new DummyTeam();

            team.Name = "Test Team #1";
            team.List.Add(player);
            TeamVM teamVM = new TeamVM {
                Model = team
            };

            templatesController.ViewModel.ViewModels.Add(teamVM);

            DummyTeam team2        = team.Clone();
            string    expectedName = "Test Team #2";

            team2.Name   = expectedName;
            team2.Static = true;
            var evt = new UpdateEvent <Team> ()
            {
                Object = team2,
                Force  = true
            };

            // Action
            App.Current.EventsBroker.Publish(evt);

            // Assert
            mockDialogs.Verify(m => m.QuestionMessage(It.IsAny <string> (), null, It.IsAny <DummyTemplatesController> ()), Times.Once());
        }
Exemplo n.º 11
0
        public TeamInformation(int idTeam)
        {
            InitializeComponent();

            TeamVM teamVM = new TeamVM(idTeam);

            BindingContext = teamVM;
        }
Exemplo n.º 12
0
        void Select(TeamVM teamVM)
        {
            TreeIter iter;

            if (GetIterFromTeam(teamVM, out iter))
            {
                teamseditortreeview.Selection.SelectIter(iter);
            }
        }
Exemplo n.º 13
0
        void Remove(TeamVM teamVM)
        {
            TreeIter iter;

            if (GetIterFromTeam(teamVM, out iter))
            {
                teamsStore.Remove(ref iter);
                teamVM.PropertyChanged -= HandleTeamPropertyChanged;
            }
        }
Exemplo n.º 14
0
        internal static Dictionary <string, string> CreateTeam(TeamVM team)
        {
            var response = new Dictionary <string, string>();

            if (string.IsNullOrEmpty(team.TeamName))
            {
                response.Add("teamname", "Team name cannot be null");
            }

            return(response);
        }
Exemplo n.º 15
0
        public static TeamVM MapToVM(Team team)
        {
            TeamVM teamVM = new TeamVM()
            {
                Image   = team.Image,
                Name    = team.Name,
                TeamId  = team.TeamId,
                Acronym = team.Acronym
            };

            return(teamVM);
        }
Exemplo n.º 16
0
        public static Team MapFromVM(TeamVM teamVM)
        {
            Team team = new Team()
            {
                Image   = teamVM.Image,
                Name    = teamVM.Name,
                TeamId  = teamVM.TeamId,
                Acronym = teamVM.Acronym
            };

            return(team);
        }
Exemplo n.º 17
0
        public void TestExport_TemplateSelectedToNewFile_Exported()
        {
            // Arrange
            TeamVM team = PrepareExport();

            // Act
            templatesController.ViewModel.ExportCommand.Execute();
            var exportedTeam = Serializer.Instance.Load <DummyTeam> (tempFile);

            // Assert
            Assert.AreEqual(team.Model, exportedTeam);
        }
Exemplo n.º 18
0
        public async Task <ActionResult> Detail(int id)
        {
            var team = await _teamsService.GetById(id);

            if (team == null)
            {
                return(NotFound());
            }

            TeamVM teamVM = _mapper.Map <TeamVM>(team);

            return(View(teamVM));
        }
Exemplo n.º 19
0
        public ActionResult Edit(int id)
        {
            var team = teamManager.GetTeam(id);

            if (team != null)
            {
                var vm = new TeamVM {
                    Name = team.Name, Id = team.Id
                };
                return(PartialView(vm));
            }
            return(View("NotFound"));
        }
Exemplo n.º 20
0
 bool GetIterFromTeam(TeamVM team, out TreeIter iter)
 {
     teamsStore.GetIterFirst(out iter);
     while (teamsStore.IterIsValid(iter))
     {
         if ((teamsStore.GetValue(iter, COL_TEAM) as TeamVM).Model.Equals(team.Model))
         {
             return(true);
         }
         teamsStore.IterNext(ref iter);
     }
     return(false);
 }
 public string Put([FromBody] Fixture entity)
 {
     if (_fixtureService.Update(entity))
     {
         TeamVM tvm = new TeamVM();
         tvm.Team1Id    = entity.Home;
         tvm.Team2Id    = entity.Away;
         tvm.Team1Score = entity.HomeScore;
         tvm.Team2Score = entity.AwayScore;
         _teamService.UpdatePoint(tvm);
     }
     return(string.Empty);
 }
Exemplo n.º 22
0
        public IActionResult View(int id)
        {
            var team = this._teamManager.GetTeam(id);

            if (team != null)
            {
                var vm = new TeamVM {
                    Id = team.Id, Name = team.Name, IsPublic = team.IsPublic, IsRequestingUserTeamOwner = team.IsRequestingUserTeamOwner
                };

                return(View(vm));
            }
            return(View("NotFound"));
        }
        public bool UpdatePoint(TeamVM entity)
        {
            var homeTeam = Get(entity.Team1Id);

            homeTeam.Point     += entity.PointHome;
            homeTeam.ChangeDate = DateTime.Now;

            var awayTeam = Get(entity.Team2Id);

            awayTeam.Point     += entity.PointAway;
            awayTeam.ChangeDate = DateTime.Now;

            return((context.SaveChanges() > 0) ? true : false);
        }
Exemplo n.º 24
0
        public GetFavouriteTeamTaskResponse GetFavouriteTeamTask(GetFavouriteTeamTaskRequest request)
        {
            FavouriteTeamSettingsModel favouriteTeamSettingsModel = this.GetFavouriteTeamSettings();  //Convert from json

            if (favouriteTeamSettingsModel == null)
            {
                return(new GetFavouriteTeamTaskResponse());
            }
            TeamVM favouriteTeam = favouriteTeamSettingsModel.Items.Where(x => x.Cup.Name == request.Cup.Name).Select(x => x.Team).FirstOrDefault();

            return(new GetFavouriteTeamTaskResponse()//Objekt upakiraj u response i vrati ga nazad
            {
                Team = favouriteTeam
            });
        }
Exemplo n.º 25
0
        public ActionResult ViewRoster(int id)
        {
            var leagueManager = new LeagueManager();
            var manager       = new TeamManager();
            var roster        = manager.GetTeamById(id);

            var teamVM = new TeamVM();

            teamVM.Team         = roster;
            teamVM.TeamLeague   = leagueManager.GetLeagueById(teamVM.Team.LeagueId);
            teamVM.FreeAgents   = manager.GetTeamById(0);
            teamVM.Team.Players = roster.Players.OrderBy(t => t.LastName).ToList();


            return(View(teamVM));
        }
Exemplo n.º 26
0
        public void TestExport_TemplateSelected_Overwrite()
        {
            // Arrange
            TeamVM team = PrepareExport();

            using (var stream = File.AppendText(tempFile)) {
                stream.WriteLine("FOO");
            }

            // Act
            templatesController.ViewModel.ExportCommand.Execute();
            var exportedTeam = Serializer.Instance.Load <DummyTeam> (tempFile);

            // Assert
            Assert.AreEqual(team.Model, exportedTeam);
        }
 public ActionResult Create(TeamVM model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             model.Name = model.Name.Replace(" ", "");
             var teamId = _teamManager.SaveTeam(model);
             return(Json(new { Status = "Success" }));
         }
         return(View(model));
     }
     catch (Exception ex)
     {
     }
     return(Json(new { Status = "Error" }));
 }
Exemplo n.º 28
0
        public void TestExport_TemplateSelected_NotOverwrite()
        {
            // Arrange
            TeamVM team = PrepareExport();

            using (var stream = File.AppendText(tempFile)) {
                stream.WriteLine("FOO");
            }
            mockDialogs.Setup(m => m.QuestionMessage(It.IsAny <string> (), null,
                                                     It.IsAny <DummyTemplatesController> ())).
            Returns(AsyncHelpers.Return(false));


            templatesController.ViewModel.ExportCommand.Execute();

            // Assert
            Assert.IsTrue(File.Exists(tempFile));
            Assert.Throws <JsonReaderException> (() => Serializer.Instance.Load <DummyTeam> (tempFile));
        }
Exemplo n.º 29
0
        public ActionResult Index()
        {
            try
            {
                var team   = repo.GetTeam(TeamID);
                var teamVM = new TeamVM {
                    Name = team.Name, Id = team.ID
                };

                var teamMembers = team.TeamMembers.OrderBy(s => s.Member.FirstName).ToList();
                foreach (var member in teamMembers)
                {
                    var memberVM = new MemberVM();
                    memberVM.Name         = member.Member.FirstName;
                    memberVM.EmailAddress = member.Member.EmailAddress;
                    memberVM.AvatarHash   = UserService.GetAvatarUrl(member.Member.Avatar, 30);
                    memberVM.JoinedDate   = member.CreatedDate.ToShortDateString();
                    if (member.Member.LastLoginDate.HasValue)
                    {
                        memberVM.LastLoginDate = member.Member.LastLoginDate.Value.ToString("g");
                    }

                    teamVM.Members.Add(memberVM);
                }

                var membersNotJoinedList = repo.GetTeamMembersWhoHasntJoined(TeamID).OrderBy(s => s.EmailAddress).ToList();
                foreach (var member in membersNotJoinedList)
                {
                    var invitation = new MemberInvitation {
                        EmailAddress = member.EmailAddress, DateInvited = member.CreatedDate.ToString("g")
                    };
                    invitation.AvatarHash = UserService.GetImageSource(member.EmailAddress);
                    teamVM.MembersInvited.Add(invitation);
                }
                return(View(teamVM));
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(View("Error"));
            }
        }
Exemplo n.º 30
0
        public TeamVM PrepareExport()
        {
            Utils.PlayerDummy player = new Utils.PlayerDummy();
            DummyTeam         team   = new DummyTeam();

            team.List.Add(player);
            TeamVM teamVM = new TeamVM {
                Model = team
            };

            templatesController.ViewModel.ViewModels.Add(teamVM);
            templatesController.ViewModel.Selection.Add(teamVM);
            tempFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            tempFile = Path.ChangeExtension(tempFile, null);
            mockDialogs.Setup(m => m.SaveFile(It.IsAny <string> (), It.IsAny <string> (),
                                              It.IsAny <string> (), It.IsAny <string> (),
                                              It.IsAny <string []> ())).
            Returns(tempFile);
            return(teamVM);
        }
Exemplo n.º 31
0
 void Add(TeamVM teamVM)
 {
     teamsStore.AppendValues (teamVM, teamVM.Editable);
 }
Exemplo n.º 32
0
 void Select(TeamVM teamVM)
 {
     TreeIter iter;
     teamsStore.GetIterFirst (out iter);
     while (teamsStore.IterIsValid (iter)) {
         if ((teamsStore.GetValue (iter, COL_TEAM) as TeamVM).Model.Equals (teamVM.Model)) {
             teamseditortreeview.Selection.SelectIter (iter);
             break;
         }
         teamsStore.IterNext (ref iter);
     }
 }
Exemplo n.º 33
0
 void Remove(TeamVM teamVM)
 {
     TreeIter iter;
     teamsStore.GetIterFirst (out iter);
     while (teamsStore.IterIsValid (iter)) {
         if (teamsStore.GetValue (iter, COL_TEAM) == teamVM) {
             teamsStore.Remove (ref iter);
             break;
         }
         teamsStore.IterNext (ref iter);
     }
 }