Ejemplo n.º 1
0
 public BannedCloud(Ban ban, string id)
 {
     InitializeComponent();
     ForStaff.Visibility = App.Connection.SessionController.CurrentSession.IsStaff
         ? Visibility.Visible
         : Visibility;
     sId = id;
     CloudName.Text = App.Connection.ModelController.Clouds[id].Name;
     BanDue.Text = ban.Due.Value.ToShortDateString();
     BanReason.Text = "\"" + ban.Reason + "\"";
     CloudRules.Text = App.Connection.MessageController.CurrentCloud.Cloud.Rules != null
         ? App.Connection.MessageController.CurrentCloud.Cloud.Rules.Replace("\n", "\r\n")
         : "";
 }
Ejemplo n.º 2
0
        private async void AttemptBan(object sender, RoutedEventArgs e)
        {
            if (BanCal.SelectedDate == null)
            {
                App.Connection.NotificationController.Notification.Notify("You have to select a date!");
                return;
            }
            
            if (String.IsNullOrEmpty(BanReason.Text))
            {
                App.Connection.NotificationController.Notification.Notify("You can't leave the reason blank!");
                return;
            }
            if (
                MessageBox.Show(String.Format("Ban @{0} for \"{1}\" until {2}?", 
                Self.Username, 
                BanReason.Text,
                BanCal.SelectedDate)) != MessageBoxResult.Yes) return;
            var ban = new Ban(Self.Id)
                          {
                              OffenderId = Self.Id,
                              Reason = BanReason.Text,
                              Due = BanCal.SelectedDate.Value.ToUniversalTime()
                          };
            var client = new HttpClient
                             {
                                 DefaultRequestHeaders =
                                     {
                                         {"Accept", "application/json"},
                                         {"X-Auth-Token", App.Connection.SessionController.CurrentSession.AuthToken}
                                     }
                             };
            var response = await client.PostAsync(
                    Endpoints.CloudBan.Replace("[:id]", App.Connection.MessageController.CurrentCloud.Cloud.Id), new JsonContent(ban));

            var responseObject =
                JsonConvert.DeserializeObjectAsync<WebResponse<Ban>>(response.Content.ReadAsStringAsync().Result);
            if (responseObject.Result.Flash != null)
            {
                App.Connection.NotificationController.Notification.Notify(responseObject.Result.Flash.Message);
                return;
            }
            App.Connection.MessageController[App.Connection.MessageController.CurrentCloud.Cloud].Bans.Add(responseObject.Result.Result);
        }