public async Task <FieldSettingsViewModel> FillFailedSettingsModel(FieldSettingsViewModel model) { var project = await ProjectRepository.GetProjectWithFieldsAsync(CurrentProject.ProjectId); if (project == null) { return(null); } return(FillSettingsModel(project, model)); }
/// <summary> /// Set settings /// </summary> public async Task SettingsHandleAsync(FieldSettingsViewModel viewModel) { await Service.SetFieldSettingsAsync(new FieldSettingsRequest() { DescriptionField = viewModel.DescriptionField > 0 ? viewModel.DescriptionField : (int?)null, NameField = viewModel.NameField > 0 ? viewModel.NameField : (int?)null, LegacyModelEnabled = viewModel.LegacyModelEnabled, ProjectId = CurrentProject.ProjectId, }); }
public async Task <ActionResult> Settings(FieldSettingsViewModel viewModel) { if (!ModelState.IsValid) { return(await ViewIfFound(Manager.FillFailedSettingsModel(viewModel))); } try { await Manager.SettingsHandleAsync(viewModel); return(ReturnToIndex()); } catch (Exception exception) { ModelState.AddException(exception); return(View(await Manager.FillFailedSettingsModel(viewModel))); } }
/// <summary> /// Page with field settings /// </summary> public async Task <FieldSettingsViewModel> SettingsPagesAsync() { var project = await ProjectRepository.GetProjectWithFieldsAsync(CurrentProject.ProjectId); if (project == null) { return(null); } var viewModel = new FieldSettingsViewModel { NameField = project.Details.CharacterNameField?.ProjectFieldId ?? -1, DescriptionField = project.Details.CharacterDescription?.ProjectFieldId ?? -1, LegacyModelEnabled = project.Details.CharacterNameLegacyMode, }; return(FillSettingsModel(project, viewModel)); }
private FieldSettingsViewModel FillSettingsModel(Project project, FieldSettingsViewModel viewModel) { var fields = project.GetOrderedFields(); viewModel.PossibleDescriptionFields = ToSelectListItems( fields.Where(f => f.FieldType == ProjectFieldType.Text && f.FieldBoundTo == FieldBoundTo.Character), "Нет поля с описанием персонажа" ).SetSelected(project.Details.CharacterDescription?.ProjectFieldId); viewModel.PossibleNameFields = ToSelectListItems( fields.Where(f => f.FieldType == ProjectFieldType.String && f.FieldBoundTo == FieldBoundTo.Character), "Имя персонажа берется из имени игрока" ).SetSelected(project.Details.CharacterNameField?.ProjectFieldId); // cast needed to call correct method var _ = FillFromProject(project, viewModel); return(viewModel); }