private void DeleteTitleButton_Click(object sender, System.Windows.RoutedEventArgs e) { Button button = (Button)sender; UserTitleModel title = (UserTitleModel)button.DataContext; ChannelSession.Settings.UserTitles.Remove(title); this.RefreshTitleList(); }
public UserTitleViewModel(UsersSettingsControlViewModel viewModel, UserTitleModel title) { this.viewModel = viewModel; this.Title = title; this.DeleteCommand = this.CreateCommand(() => { this.viewModel.DeleteTitle(this); }); }
public UserTitleViewModel(UsersSettingsControlViewModel viewModel, UserTitleModel title) { this.viewModel = viewModel; this.Title = title; this.DeleteCommand = this.CreateCommand((parameter) => { this.viewModel.DeleteTitle(this); return(Task.FromResult(0)); }); }
private async void AddTitleButton_Click(object sender, System.Windows.RoutedEventArgs e) { await this.Window.RunAsyncOperation(async() => { if (string.IsNullOrEmpty(this.TitleNameTextBox.Text)) { await MessageBoxHelper.ShowMessageDialog("A name for the title must be specified"); return; } if (this.TitleRoleComboBox.SelectedIndex < 0) { await MessageBoxHelper.ShowMessageDialog("A role for the title must be specified"); return; } int months = 0; MixerRoleEnum role = EnumHelper.GetEnumValueFromString <MixerRoleEnum>((string)this.TitleRoleComboBox.SelectedItem); if (role == MixerRoleEnum.Follower || role == MixerRoleEnum.Subscriber) { if (!int.TryParse(this.TitleMinimumMonthsTextBox.Text, out months) || months < 0) { await MessageBoxHelper.ShowMessageDialog("A valid amount of months for the title must be specified"); return; } } if (this.titles.Any(t => t.Name.Equals(this.TitleNameTextBox.Text))) { await MessageBoxHelper.ShowMessageDialog("A title with the same name already exists"); return; } if (this.titles.Any(t => t.Role.Equals(role))) { UserTitleModel existingTitle = this.titles.FirstOrDefault(t => t.Role.Equals(role)); if (existingTitle.Role == MixerRoleEnum.Follower || existingTitle.Role == MixerRoleEnum.Subscriber) { if (existingTitle.Months == months) { await MessageBoxHelper.ShowMessageDialog("A title with the same role & months already exists"); return; } } else { await MessageBoxHelper.ShowMessageDialog("A title with the same role already exists"); return; } } ChannelSession.Settings.UserTitles.Add(new UserTitleModel(this.TitleNameTextBox.Text, role, months)); this.TitleNameTextBox.Text = string.Empty; this.TitleRoleComboBox.SelectedIndex = -1; this.TitleMinimumMonthsTextBox.Text = string.Empty; this.RefreshTitleList(); }); }
public async Task<HttpResponseMessage> Post(UserTitleModel entity) { entity.ID = Guid.NewGuid().ToString("N"); try { var result = await Service.InsertAsync(Mapper.Map<IUserTitle>(entity)); if (result == 0) return Request.CreateResponse(HttpStatusCode.BadRequest, "Add operation error."); return Request.CreateResponse(HttpStatusCode.OK, result); } catch (Exception e) { return Request.CreateResponse(HttpStatusCode.BadRequest, e.Message); } }
public async Task<HttpResponseMessage> Put(string ID, UserTitleModel entity) { try { if (ID != entity.ID) { return Request.CreateResponse(HttpStatusCode.BadRequest, "IDs do not match."); } var result = await Service.UpdateAsync(Mapper.Map<IUserTitle>(entity)); if (result == 1) { return Request.CreateResponse(HttpStatusCode.OK, entity); } else { return Request.CreateResponse(HttpStatusCode.InternalServerError, "PUT unsuccessful."); } } catch (Exception e) { return Request.CreateResponse(HttpStatusCode.BadRequest, e.ToString()); } }