Exemplo n.º 1
0
        public async Task <ActionResult> Create(GameFieldCreateViewModel viewModel)
        {
            var project = await ProjectRepository.GetProjectAsync(viewModel.ProjectId);

            var error = AsMaster(project, pa => pa.CanChangeFields);

            if (error != null)
            {
                return(error);
            }
            if (!ModelState.IsValid)
            {
                return(View(FillFromProject(project, viewModel)));
            }
            try
            {
                await FieldSetupService.AddField(project.ProjectId,
                                                 (ProjectFieldType)viewModel.FieldViewType, viewModel.Name,
                                                 viewModel.DescriptionEditable,
                                                 viewModel.CanPlayerEdit, viewModel.CanPlayerView,
                                                 viewModel.IsPublic, (FieldBoundTo)viewModel.FieldBoundTo,
                                                 (MandatoryStatus)viewModel.MandatoryStatus,
                                                 viewModel.ShowForGroups.GetUnprefixedGroups(), viewModel.ValidForNpc,
                                                 viewModel.FieldBoundTo == FieldBoundToViewModel.Character && viewModel.CanPlayerView,
                                                 viewModel.ShowForUnApprovedClaim);

                return(ReturnToIndex(project));
            }
            catch (Exception exception)
            {
                ModelState.AddException(exception);
                return(View(FillFromProject(project, viewModel)));
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Create(GameFieldCreateViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(await ViewIfFound(Manager.FillFailedModel(viewModel)));
            }
            try
            {
                var request = new CreateFieldRequest(
                    viewModel.ProjectId,
                    (ProjectFieldType)viewModel.FieldViewType,
                    viewModel.Name,
                    viewModel.DescriptionEditable,
                    viewModel.CanPlayerEdit,
                    viewModel.CanPlayerView,
                    viewModel.IsPublic,
                    (FieldBoundTo)viewModel.FieldBoundTo,
                    (MandatoryStatus)viewModel.MandatoryStatus,
                    viewModel.ShowForGroups.GetUnprefixedGroups(),
                    viewModel.ValidForNpc,
                    viewModel.FieldBoundTo == FieldBoundToViewModel.Character && viewModel.CanPlayerView,
                    viewModel.ShowForUnApprovedClaim,
                    viewModel.Price,
                    viewModel.MasterDescriptionEditable,
                    programmaticValue: null);

                await FieldSetupService.AddField(request);

                return(ReturnToIndex());
            }
            catch (Exception exception)
            {
                ModelState.AddException(exception);
                return(View(await Manager.FillFailedModel(viewModel)));
            }
        }
Exemplo n.º 3
0
 private static GameFieldCreateViewModel FillFromProject(Project project, GameFieldCreateViewModel viewModel)
 {
     viewModel.ProjectId = project.ProjectId;
     return(viewModel);
 }