Esempio n. 1
0
        public async Task <int> Create(VmScenarioCreate model)
        {
            if (model == null)
            {
                throw new HttpStatusCodeException(HttpStatusCode.BadRequest);
            }

            var productIds = new List <int>();

            // should we move that logic into the service layer or do we keep it in the view?
            if (model.UploadedFile != null)
            {
                var products = await _fileUploadService.GetContentsByGuid(model.UploadedFile.Value);

                productIds = products.Select(x => x.ProductId).ToList();
            }

            if (model.HierarchyIds.Count + productIds.Count == 0)
            {
                throw new Exception("No product in scope for scenario");
            }

            var scenarioId = await _scenarioWebService.Create(model.ScenarioName, model.Week, model.ScheduleMask,
                                                              model.ScheduleWeekMin, model.ScheduleWeekMax,
                                                              model.MarkdownCountStartWeek, model.DefaultMarkdownType,
                                                              model.DefaultDecisionState,
                                                              model.AllowPromoAsMarkdown, model.MinimumPromoPercentage,
                                                              _organisationDataProvider.OrganisationId.Value,
                                                              _organisationDataProvider.UserId.Value,
                                                              productIds, model.HierarchyIds);

            if (model.UploadedFile != null)
            {
                await _fileUploadService.useForScenario(model.UploadedFile.Value, scenarioId);
            }
            return(scenarioId);
        }