コード例 #1
0
        public async Task <IActionResult> EditScenario(string id, ScenarioModel model)
        {
            var map = await MapModel.GetAsync(AppSettings.DefaultRepo);

            var mapScenario = map.FindScenario(id);

            if (mapScenario != null)
            {
                mapScenario.Title   = model.Title;
                mapScenario.Summary = model.Summary;

                using (await LockingService.LockAsync())
                {
                    await map.SaveAsync();

                    await ScenarioModel.SaveContentsAsync(id, AppSettings.DefaultRepo, model.Contents);

                    await ChangesService.Get(AppSettings.DefaultRepo).PushChangesAsync();
                }
            }

            dynamic parameters = new ExpandoObject();

            parameters.id = id;
            return(RedirectToAction(nameof(ViewScenario), parameters));
        }
コード例 #2
0
        public async Task <IActionResult> EditProposal(string id, ProposalModel model)
        {
            var map = await MapModel.GetAsync(AppSettings.DefaultRepo);

            var existing = map.Proposals?.FirstOrDefault(i => i.Id == id);

            if (existing != null)
            {
                existing.Title = model.Title;

                using (await LockingService.LockAsync())
                {
                    await map.SaveAsync();

                    await BaseContentsModel.SaveContentsAsync(id, AppSettings.DefaultRepo, model.Contents);

                    await ChangesService.Get(AppSettings.DefaultRepo).PushChangesAsync();
                }
            }

            dynamic parameters = new ExpandoObject();

            parameters.id = id;
            return(RedirectToAction(nameof(ViewProposal), parameters));
        }
コード例 #3
0
        public async Task <IActionResult> CreateProposal(ProposalModel model)
        {
            var map = await MapModel.GetAsync(AppSettings.DefaultRepo);

            var id = Guid.NewGuid().ToString();

            if (map.Proposals == null)
            {
                map.Proposals = new List <MapProposalModel>();
            }
            map.Proposals.Add(new MapProposalModel()
            {
                Id    = id,
                Title = model.Title
            });

            using (await LockingService.LockAsync())
            {
                await map.SaveAsync();

                await BaseContentsModel.SaveContentsAsync(id, AppSettings.DefaultRepo, model.Contents);

                await ChangesService.Get(AppSettings.DefaultRepo).PushChangesAsync();
            }

            dynamic parameters = new ExpandoObject();

            parameters.id = id;
            return(RedirectToAction(nameof(ViewProposal), parameters));
        }
コード例 #4
0
        public async Task <IActionResult> EditProposalExample(string scenarioId, string proposalId, AddProposalExampleModel model)
        {
            var scenario = await ScenarioModel.GetAsync(AppSettings.DefaultRepo, scenarioId);

            if (scenario == null)
            {
                return(NotFound());
            }

            var proposalExample = scenario.Proposals?.FirstOrDefault(i => i.ProposalId == proposalId);

            if (proposalExample == null)
            {
                return(NotFound());
            }

            using (await LockingService.LockAsync())
            {
                await BaseContentsModel.SaveContentsAsync(proposalExample.Id, AppSettings.DefaultRepo, model.Contents);

                await ChangesService.Get(AppSettings.DefaultRepo).PushChangesAsync();
            }

            dynamic parameters = new ExpandoObject();

            parameters.scenarioId = scenarioId;
            parameters.proposalId = proposalId;
            return(RedirectToAction(actionName: nameof(ViewProposalExample), routeValues: parameters));
        }
コード例 #5
0
        public async Task <IActionResult> AddChildScenario(string parentId, ScenarioModel model)
        {
            var map = await MapModel.GetAsync(AppSettings.DefaultRepo);

            var parent = map.FindScenario(parentId);

            if (parent != null)
            {
                if (parent.Children == null)
                {
                    parent.Children = new List <MapScenarioModel>();
                }

                var newScenario = new MapScenarioModel()
                {
                    Id      = Guid.NewGuid().ToString(),
                    Title   = model.Title,
                    Summary = model.Summary
                };

                parent.Children.Add(newScenario);

                using (await LockingService.LockAsync())
                {
                    await map.SaveAsync();

                    await ScenarioModel.SaveContentsAsync(newScenario.Id, AppSettings.DefaultRepo, model.Contents);

                    await ChangesService.Get(AppSettings.DefaultRepo).PushChangesAsync();
                }

                dynamic parameters = new ExpandoObject();
                parameters.id = newScenario.Id;
                return(RedirectToAction(nameof(ViewScenario), parameters));
            }

            dynamic failedParameters = new ExpandoObject();

            failedParameters.id = parentId;
            return(RedirectToAction(nameof(ViewScenario), failedParameters));
        }
コード例 #6
0
        public async Task <IActionResult> AddProposalExample(string scenarioId, AddProposalExampleModel model)
        {
            if (string.IsNullOrWhiteSpace(model.ProposalId))
            {
                throw new Exception("You must pick a proposal");
            }

            var map = await MapModel.GetAsync(AppSettings.DefaultRepo);

            var parent = map.FindScenario(scenarioId);

            if (parent != null)
            {
                if (parent.ProposalExamples == null)
                {
                    parent.ProposalExamples = new List <MapProposalExampleModel>();
                }

                var newProposal = new MapProposalExampleModel()
                {
                    ProposalId = model.ProposalId
                };

                parent.ProposalExamples.Add(newProposal);

                using (await LockingService.LockAsync())
                {
                    await map.SaveAsync();

                    await BaseContentsModel.SaveContentsAsync(parent.Id + "-" + model.ProposalId, AppSettings.DefaultRepo, model.Contents);

                    await ChangesService.Get(AppSettings.DefaultRepo).PushChangesAsync();
                }
            }

            dynamic parameters = new ExpandoObject();

            parameters.scenarioId = scenarioId;
            parameters.proposalId = model.ProposalId;
            return(RedirectToAction(actionName: nameof(ViewProposalExample), routeValues: parameters));
        }