示例#1
0
 public AddEvent()
 {
     this.InitializeComponent();
     this.NavigationCacheMode = NavigationCacheMode.Required;
     ruserteam = new CollectionUsersTeam();
     rtemplate = new TemplateEvents();
     mlibrary = new methodLibrary();
     APILibrary = new Library_APICall();
     opponent_id_map = new Hashtable();
     location_id_map = new Hashtable();
     game_type_code = 0;
     opponentAvailable = false;
     locationAvailable = false;
     //opponents = new List<string>();
 }
示例#2
0
        private async void SaveEvent_Click(object sender, RoutedEventArgs e)
        {
            if (opponentAvailable == false || locationAvailable == false)
            {
                if (opponentAvailable == false && locationAvailable == true)
                {
                    Debug.WriteLine("You need to add a location.");
                    var messageDialog = new MessageDialog("You need to add a new location or choose an existing one.");
                    messageDialog.Commands.Add(new UICommand("Try again", new UICommandInvokedHandler(this.CommandInvokedHandler)));
                    await messageDialog.ShowAsync();

                }
                else if (opponentAvailable == true && locationAvailable == false)
                {
                    Debug.WriteLine("You need to add an opponent.");
                    var messageDialog = new MessageDialog("You need to add a new opponent or pick an existing opponent.");
                    messageDialog.Commands.Add(new UICommand("Try again", new UICommandInvokedHandler(this.CommandInvokedHandler)));
                    await messageDialog.ShowAsync();
                }
                else
                {
                    Debug.WriteLine("You need to add a location and an opponent to create a new game");
                    var messageDialog = new MessageDialog("You need to pick a location and an opponent.");
                    messageDialog.Commands.Add(new UICommand("Try again", new UICommandInvokedHandler(this.CommandInvokedHandler)));
                    await messageDialog.ShowAsync();
                }
            }
            else
            {
                ComboBoxItem cbt = (ComboBoxItem)TimeZoneCombo.SelectedItem;
                string locationbt = (string)locationcombobox.SelectedItem;
                string opponentbt = (string)opponentComboBox.SelectedItem;
                string res = await mlibrary.readFile((string)ApplicationData.Current.LocalSettings.Values["eventTemplateFile"]);
                RootObjectEvents revents = Events.eventsDataDeserializer(res);
                rtemplate = revents.collection.template;
                Hashtable rtemplate_ht = new Hashtable();
                for (int i = 0; i < rtemplate.data.Count; i++)
                {
                    rtemplate_ht.Add(rtemplate.data[i].name, i);
                }
                ///get start_date. Then get start time and add it to start date.
                DateTimeOffset dts = gameDate.Date;
                DateTime game_date = dts.Date;

                if (tbd.IsChecked == true)
                {

                    Debug.WriteLine("game date : " + game_date);
                    rtemplate.data[(int)rtemplate_ht["is_tbd"]].value = true;
                }
                else
                {
                    TimeSpan ts = gameTime.Time;
                    game_date = game_date + ts;
                    Debug.WriteLine("game date : " + game_date);
                    rtemplate.data[(int)rtemplate_ht["is_tbd"]].value = ((false).ToString()).ToLower();
                }
                string gamedate = null;
                try
                {
                    gamedate = String.Format("{0:yyyy}", game_date) + "-" + String.Format("{0:MM}", game_date) + "-" + String.Format("{0:dd}", game_date) + "T" + String.Format("{0:HH}", game_date) + ":" + String.Format("{0:mm}", game_date) + ":" + String.Format("{0:ss}", game_date) + "Z";
                }
                catch (Exception exe)
                {
                    Debug.WriteLine(exe);
                }
                rtemplate.data[(int)rtemplate_ht["start_date"]].value = gamedate;
                /// done


                rtemplate.data[(int)rtemplate_ht["time_zone"]].value = cbt == null ? null : methodLibrary.getIANATimeZone((string)cbt.Content); ;
                rtemplate.data[(int)rtemplate_ht["is_game"]].value = false;
                if (opponent_id_map.Contains((string)opponentbt))
                {
                    opponentAvailable = true;
                    rtemplate.data[(int)rtemplate_ht["opponent_id"]].value = opponent_id_map[(string)opponentbt];
                    Debug.WriteLine(opponentbt);
                }
                else
                {
                    opponentAvailable = false;
                    Debug.WriteLine("Opponent doesn't exist");
                }
                if (location_id_map.Contains((string)locationbt))
                {
                    locationAvailable = true;
                    rtemplate.data[(int)rtemplate_ht["location_id"]].value = location_id_map[(string)locationbt];
                    Debug.WriteLine(rtemplate.data[(int)rtemplate_ht["location_id"]].value);
                }
                else
                {
                    locationAvailable = false;
                    Debug.WriteLine("Location doesn't exist");
                }
                //DateTime dtarrive = new DateTime(0, 0, 0, durationHour, durationMinute);
                //DateTime dtduration = DateTime.ParseExact(""+"\"" +durationHour + "\":\"" + durationMinute + "\"", "HH:mm", System.Globalization.CultureInfo.InvariantCulture);
                rtemplate.data[(int)rtemplate_ht["repeating_type_code"]].value = null;
                rtemplate.data[(int)rtemplate_ht["repeating_until"]].value = null;
                rtemplate.data[(int)rtemplate_ht["team_id"]].value = teamid;
                rtemplate.data[(int)rtemplate_ht["minutes_to_arrive_early"]].value = minutes_to_arrive_early.Text == "" ? "0" : (minutes_to_arrive_early.Text);               
                rtemplate.data[(int)rtemplate_ht["name"]].value = eventName.Text;
                rtemplate.data[(int)rtemplate_ht["label"]].value = shortLabel.Text;
                rtemplate.data[(int)rtemplate_ht["additional_location_details"]].value = location_details.Text;
                rtemplate.data[(int)rtemplate_ht["uniform"]].value = "\"\"";
                rtemplate.data[(int)rtemplate_ht["game_type_code"]].value = null;
                rtemplate.data[(int)rtemplate_ht["is_canceled"]].value = false;
                rtemplate.data[(int)rtemplate_ht["notes"]].value = NotesTextBox.Text;
                rtemplate.data[(int)rtemplate_ht["uniform"]].value = UniformTextBox.Text; 
                rtemplate.data[(int)rtemplate_ht["duration_in_minutes"]].value = (int.Parse((durationHour.Text == "" ? 0.ToString() : durationHour.Text))) * 60 + (int.Parse((durationMinute.Text == "" ? 0.ToString() : durationMinute.Text)));
                res = Events.templateeventDataSerializer(rtemplate);
                Debug.WriteLine("is tbd : " + rtemplate.data[(int)rtemplate_ht["is_tbd"]].value);
                res = "{ \"template\":{ \"data\":[{\"name\":\"is_game\",\"value\":false},{\"name\":\"start_date\",\"value\":\"" + rtemplate.data[(int)rtemplate_ht["start_date"]].value + "\"},{\"name\":\"is_tbd\",\"value\":" + rtemplate.data[(int)rtemplate_ht["is_tbd"]].value + "},{\"name\":\"name\",\"value\":\"" + rtemplate.data[(int)rtemplate_ht["name"]].value + "\"},{\"name\":\"label\",\"value\":\"" + rtemplate.data[(int)rtemplate_ht["label"]].value + "\"},{\"name\":\"minutes_to_arrive_early\",\"value\":" + rtemplate.data[(int)rtemplate_ht["minutes_to_arrive_early"]].value + "},{\"name\":\"duration_in_minutes\",\"value\":" + rtemplate.data[(int)rtemplate_ht["duration_in_minutes"]].value + "},{\"name\":\"notes\",\"value\":\"" + rtemplate.data[(int)rtemplate_ht["notes"]].value + "\"},{\"name\":\"uniform\",\"value\":\"" + rtemplate.data[(int)rtemplate_ht["uniform"]].value + "\"},{\"name\":\"team_id\",\"value\":" + rtemplate.data[(int)rtemplate_ht["team_id"]].value + "},{\"name\":\"location_id\",\"value\":" + rtemplate.data[(int)rtemplate_ht["location_id"]].value + "},{\"name\":\"opponent_id\",\"value\":" + rtemplate.data[(int)rtemplate_ht["opponent_id"]].value + "},{\"name\":\"time_zone\",\"value\":\"" + rtemplate.data[(int)rtemplate_ht["time_zone"]].value + "\"},{\"name\":\"type\",\"value\":\"event\"}]}}";
                Debug.WriteLine(res);
                //AddGameProgressRing.IsActive = true;
                if (opponentAvailable == false || locationAvailable == false)
                {
                    if (opponentAvailable == false && locationAvailable == true)
                    {
                        Debug.WriteLine("You need to add a location.");
                    }
                    if (opponentAvailable == true && locationAvailable == false)
                    {
                        Debug.WriteLine("You need to add an opponent.");
                    }
                    else
                    {
                        Debug.WriteLine("You need to add a location and an opponent to create a new game");
                    }
                }
                else if ((string)rtemplate.data[(int)rtemplate_ht["name"]].value == "")
                {
                    Debug.WriteLine("You need to add an Event Name");
                }
                else
                {
                    try
                    {
                        bool r = await APILibrary.apiPOST((string)ApplicationData.Current.LocalSettings.Values["Tokens"], res, "https://api.teamsnap.com/v3/events");
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex);
                    }
                    NotesTextBox.Text = "";
                    UniformTextBox.Text = "";
                    minutes_to_arrive_early.Text = "";
                    eventName.Text = "";
                    shortLabel.Text = "";
                    //locationautosuggestbox.Text = "";
                    location_details.Text = "";
                    //AddGameProgressRing.IsActive = false;
                    Frame rootFrame = Window.Current.Content as Frame;
                    rootFrame.Navigate(typeof(Dashboard));
                }
                //rtemplate.data[(int)rtemplate_ht["name"]].value = 
            }
        }
示例#3
0
 public static string templateeventDataSerializer(TemplateEvents rtemplate)
 {
     string response = JsonConvert.SerializeObject(rtemplate);
     return response;
 }