private async void OpenCloseOperations(object value) { switch (value.ToString()) { case "Edit": if (SelectedTeam != null) { try { await GetSiteManagers(); ID = SelectedTeam.ID; Title = SelectedTeam.Name; ColSpan = 1; OperationsVisibility = "Visible"; var linkages = await linkageApiHelper.GetTeamSiteManagersByTeamID(ParentLayout.LoggedInUser.Token, SelectedTeam.ID); foreach (var linkage in linkages) { linkage.SiteManager.IsChecked = true; SiteManagers.FirstOrDefault(s => s.ID == linkage.SiteManager.ID).IsChecked = true; } SetCheckedText(null); IsUpdate = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("Please select a record to edit", "Select Record", MessageBoxButton.OK, MessageBoxImage.Warning); } break; case "Create": ID = 0; IsUpdate = false; ColSpan = 1; OperationsVisibility = "Visible"; ClearFields(); await GetSiteManagers(); break; default: ColSpan = ColSpan == 1 ? 2 : 1; OperationsVisibility = OperationsVisibility == "Visible" ? "Collapsed" : "Visible"; break; } }
private void SetCheckedText(object param) { try { List <string> checkedManagers = new List <string>(); SiteManagers.Where(s => s.IsChecked).Distinct().ToList().ForEach(s => checkedManagers.Add(s.Name)); SiteManagersText = string.Join(", ", checkedManagers); } catch (Exception ex) { MessageBox.Show("Error", ex.Message, MessageBoxButton.OK, MessageBoxImage.Error); } }
private async Task CreateTeam() { try { List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("Title", Title) }; if (FieldValidation.ValidateFields(values)) { if (SiteManagers.Where(s => s.IsChecked).Count() > 0) { CanSaveTeam = false; List <TeamSiteManagersModel> teamSiteManagers = new List <TeamSiteManagersModel>(); SiteManagers.Where(s => s.IsChecked).ToList().ForEach(s => teamSiteManagers.Add( new TeamSiteManagersModel { TeamID = ID, SiteManagerID = s.ID, CreatedBy = parentLayout.LoggedInUser.Name })); TeamModel teamData = new TeamModel() { Name = Title, TeamSiteManagers = teamSiteManagers }; HttpResponseMessage result = null; if (isUpdate) { teamData.ID = ID; teamData.CreatedBy = SelectedTeam.CreatedBy; result = await apiHelper.PutTeam(ParentLayout.LoggedInUser.Token, teamData).ConfigureAwait(false); } else { teamData.CreatedBy = ParentLayout.LoggedInUser.Name; result = await apiHelper.PostTeam(ParentLayout.LoggedInUser.Token, teamData).ConfigureAwait(false); } if (result.IsSuccessStatusCode) { MessageBox.Show($"Team Saved Successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information); await GetTeams(); ClearFields(); await GetSiteManagers(); IsUpdate = false; } else { MessageBox.Show("Team Saving Failed", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } CanSaveTeam = true; } } else { MessageBox.Show("Please add atleast 1 SiteManager to the Team", "Add Managers", MessageBoxButton.OK, MessageBoxImage.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); CanSaveTeam = true; } }