public TeamsView() { InitializeComponent(); this.WidthRequest = (Application.Current as App).Width; _vm = new TeamItemViewModel(); IDownloadTeam download = new DownloadTeam(); _vm.DownloadData(download, listView); }
public IActionResult CreateTeam(string id, [FromBody] TeamItemViewModel model) { if (ModelState.IsValid) { Team t = db.Teams.Where(tm => tm.Name.Equals(model.TeamName)).FirstOrDefault(); if (t != null) { return(BadRequest("Team already exsists")); } Team team = new Team() { Name = model.TeamName }; team.TeamsRelation = new List <TeamTracerPlayer>(); if (model.players != null) { for (int i = 0; i < model.players.Count; i++) { TracerPlayer player = null; if (!string.IsNullOrEmpty(model.players[i].id)) { player = db.TracerPlayers.Find(model.players[i].id); if (player == null) { return(BadRequest("Player don't exist as a tracer player")); } } else if (!string.IsNullOrEmpty(model.players[i].summonerName)) { } else if (player == null) { return(BadRequest("Player not found")); } team.TeamsRelation.Add(new TeamTracerPlayer { Team = team, TracerPlayer = player }); } } db.Teams.Add(team); db.SaveChanges(); return(Ok(team)); } else { return(BadRequest()); } }
public void TeamsViewIsUpdated() { //FixturesView ftView = new FixturesView(); TeamItemViewModel teamsView = new TeamItemViewModel(); MyListView lst = new MyListView(); //lst = global::Xamarin.Forms.NameScopeExtensions.FindByName<global::PROJEKT.Views.Controls.MyListView>(ftView, "listView"); DownloadTeams downresults = new DownloadTeams(); teamsView.DownloadData(downresults, lst); List <CustomTeam> cstlst = (List <CustomTeam>)lst.ItemsSource; Assert.AreEqual(cstlst[0].Name, downresults.results.Teams[0].Name); }
public void EntityUpdated(teamList updatedEntities) { Trace.WriteLine("Updated Team"); foreach (var entry in updatedEntities) { switch (entry.Item1) { case EntityState.Added: { using (var db = new ApplicationDbContext()) { var dbTeam = db.Teams.FindAsync(entry.Item2.Id); //Add Team to list var teamItem = new TeamItemViewModel(dbTeam.Result); //This shouldn't ever be null as we set it when we create a team (get owner's Id) var ownerId = dbTeam.Result.Members.Select(member => member.User).First().Id; //Index by UserId var indexGroup = Clients.Group(LiveUpdateHelper.GroupName(ViewModelDataType.Team, ActionType.Index, sId: ownerId)); indexGroup.AddData(ViewModelDataType.Team.ToString(), ActionType.Index.ToString(), teamItem); } } break; case EntityState.Deleted: { //Remove Team from list //Details by TeamId var detailsGroup = Clients.Group(LiveUpdateHelper.GroupName(ViewModelDataType.Team, ActionType.Details, entry.Item2.Id)); detailsGroup.RemoveData(ViewModelDataType.Team.ToString(), ActionType.Index.ToString(), entry.Item2.Id); } break; case EntityState.Modified: { using (var db = new ApplicationDbContext()) { var dbTeam = db.Teams.FindAsync(entry.Item2.Id); //Team may have also been deleted //This happens when you delete a team (all the users trigger a modified on the team) if (dbTeam.Result == null) { continue; } //Add Team to list var teamItem = new TeamItemViewModel(dbTeam.Result); //Details by TeamId var detailsGroup = Clients.Group(LiveUpdateHelper.GroupName(ViewModelDataType.Team, ActionType.Details, dbTeam.Result.Id)); detailsGroup.UpdateItemData(ViewModelDataType.Team.ToString(), ActionType.Index.ToString(), teamItem); } } break; } } }
public bool StartMonitoring_TeamViewModel(TeamsViewModel model) { //Find the user's Id string userId = HttpContext.Current.GetOwinContext().Authentication.User.Identity.GetUserId(); //Add this user as watching for Colleague Adds Groups.Add(Context.ConnectionId, LiveUpdateHelper.GroupName(userId)); //Add this user as watching updates on each colleague Groups.Add(Context.ConnectionId, LiveUpdateHelper.GroupName(ViewModelDataType.Team, ActionType.Index, sId: userId)); foreach (var team in model.Teams) { Groups.Add(Context.ConnectionId, LiveUpdateHelper.GroupName(ViewModelDataType.Team, ActionType.Details, team.Id)); } //Check if the model has changed Task.Factory.StartNew(() => { //Check if the model has changed, call update if it has using (var db = new ApplicationDbContext()) { using (var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db))) { var thisUser = userManager.FindById(userId); foreach (var userTeams in thisUser.Teams) { //Find this in model if (model.Teams.Any(item => item.Id == userTeams.Team_Id)) { var oldTeam = model.Teams.First(item => item.Id == userTeams.Team_Id); var newModel = new TeamItemViewModel(userTeams.Team); //In new and old if (!oldTeam.PublicInstancePropertiesEqual(newModel)) { //Data has changed //Push change LiveUpdateSingleton.Instance.EntityUpdated(new teamList() { new Tuple <EntityState, Team>(EntityState.Modified, userTeams.Team) }); } //Remove from model list model.Teams.Remove(oldTeam); } else { //Data has been added from database //Push add LiveUpdateSingleton.Instance.EntityUpdated(new teamList() { new Tuple <EntityState, Team>(EntityState.Added, userTeams.Team) }); } } } if (model.Teams.Any()) { //Items in the list have been deleted on the server foreach (var removedTeam in model.Teams) { //Push delete var detailsGroup = Clients.Group(LiveUpdateHelper.GroupName(ViewModelDataType.Team, ActionType.Details, removedTeam.Id)); detailsGroup.RemoveData(ViewModelDataType.Team.ToString(), ActionType.Index.ToString(), removedTeam.Id); } } } }); return(true); }
public MenuViewModel( IApplicationService applicationService = null, IAccountsService accountsService = null) { _applicationService = applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); accountsService = accountsService ?? Locator.Current.GetService <IAccountsService>(); var account = applicationService.Account; Avatar = new Avatar(account.AvatarUrl); Username = account.Username; var username = Username; Title = username; var repos = new ReactiveList <PinnedRepository>(); PinnedRepositories = repos.CreateDerivedCollection(x => { var vm = new PinnedRepositoryItemViewModel(x.Name, new Avatar(x.ImageUri)); vm.DeleteCommand .Do(_ => account.PinnedRepositories.RemoveAll(y => y.Id == x.Id)) .Subscribe(_ => repos.Remove(x)); vm.GoToCommand .Select(_ => new RepositoryViewModel(x.Owner, x.Slug)) .Subscribe(NavigateTo); return(vm); }); RefreshCommand = ReactiveCommand.CreateFromTask(_ => { repos.Reset(applicationService.Account.PinnedRepositories); return(Task.FromResult(Unit.Default)); }); var teams = new ReactiveList <User>(); Teams = teams.CreateDerivedCollection(x => { var viewModel = new TeamItemViewModel(x.Username); viewModel.GoToCommand .Select(_ => new TeamViewModel(x)) .Subscribe(NavigateTo); return(viewModel); }); TeamEvents = teams.CreateDerivedCollection(x => { var viewModel = new TeamItemViewModel(x.Username); viewModel.GoToCommand .Select(_ => new UserEventsViewModel(x.Username)) .Subscribe(NavigateTo); return(viewModel); }); LoadCommand = ReactiveCommand.CreateFromTask(t => { applicationService.Client .AllItems(x => x.Teams.GetAll()) .ToBackground(teams.Reset); applicationService.Client.Groups .GetGroups(username) .ToBackground(groups => Groups.Reset(groups.Select(ToViewModel))); return(Task.FromResult(Unit.Default)); }); GoToProfileCommand .Select(_ => new UserViewModel(username)) .Subscribe(NavigateTo); GoToMyEvents .Select(_ => new UserEventsViewModel(username)) .Subscribe(NavigateTo); GoToStarredRepositoriesCommand .Select(_ => new RepositoriesStarredViewModel()) .Subscribe(NavigateTo); GoToOwnedRepositoriesCommand .Select(_ => new UserRepositoriesViewModel(username)) .Subscribe(NavigateTo); GoToSharedRepositoriesCommand .Select(_ => new RepositoriesSharedViewModel()) .Subscribe(NavigateTo); GoToTeamsCommand .Select(_ => new TeamsViewModel()) .Subscribe(NavigateTo); GoToSettingsCommand .Select(_ => new SettingsViewModel()) .Subscribe(NavigateTo); GoToFeedbackCommand .Select(_ => new IssuesViewModel("thedillonb", "codebucket")) .Subscribe(NavigateTo); GoToGroupsCommand .Select(_ => new GroupsViewModel(username)) .Subscribe(NavigateTo); GoToExploreRepositoriesCommand .Select(_ => new RepositoriesExploreViewModel()) .Subscribe(NavigateTo); GoToDefaultTopView.Subscribe(_ => { var startupViewName = applicationService.Account.DefaultStartupView; if (!string.IsNullOrEmpty(startupViewName)) { var props = from p in GetType().GetProperties() let attr = p.GetCustomAttributes(typeof(PotentialStartupViewAttribute), true) where attr.Length == 1 select new { Property = p, Attribute = attr[0] as PotentialStartupViewAttribute }; var match = props.FirstOrDefault(x => string.Equals(startupViewName, x.Attribute.Name)); var cmd = match?.Property.GetValue(this) as ReactiveCommand <Unit, Unit>; if (cmd != null) { cmd.ExecuteNow(); return; } } //Oh no... Look for the last resort DefaultStartupViewAttribute var deprop = (from p in GetType().GetProperties() let attr = p.GetCustomAttributes(typeof(DefaultStartupViewAttribute), true) where attr.Length == 1 select new { Property = p, Attribute = attr[0] as DefaultStartupViewAttribute }).FirstOrDefault(); //That shouldn't happen... var bCmd = deprop?.Property.GetValue(this) as ReactiveCommand <Unit, Unit>; if (bCmd != null) { bCmd.ExecuteNow(); } }); }