Beispiel #1
0
        public async Task <IActionResult> PostRecommendedBundleAsync(QuestionViewModel qvm)
        {
            try
            {
                // Create question
                Question q = await _questionsRepository.AddQuestionAsync(qvm.Age, qvm.IsStudent, qvm.Income);

                // Find default bundle
                var defaultBundle = await this.FindDefaultBundleAsync(q);

                // Create custom bundle
                var cb = await this.AddCustomBundleAsync(q.QuestionId, defaultBundle.BundleId);

                // Get products
                var products = await _bundlesRepository.GetBundleProductsAsync(defaultBundle.BundleId);

                var res = new ObjectResult(new CustomBundleViewModel()
                {
                    Id = cb.CustomBundleId,
                    DefaultBundleId = cb.BundleId,
                    Products        = this.ProductsToViewModels(products)
                });

                res.StatusCode = 201;

                return(res);
            }
            catch (Exception ex)
            {
                return(new NotFoundResult());
            }
        }
Beispiel #2
0
        public async Task AddQuestionAsync(Question question)
        {
            var questionEntity = new EntityFramework.Data.Question()
            {

                Id = question.GUID,
                Time = question.Time,
                Description = question.Description,
                Answered = question.Answered,
                UserId = question.UserId
            };

            await _questionsRepository.AddQuestionAsync(questionEntity);
        }