コード例 #1
0
        public async Task <IActionResult> CreateQuiz([FromForm] QuizInfoForCreationDto inputQuizInfo)
        {
            if (inputQuizInfo == null)
            {
                return(BadRequest(Constants.QuizDataEmpty));
            }

            var quizInfoEntity = mapper.Map <QuizInfo>(inputQuizInfo);

            if (inputQuizInfo.PreviewImage != null)
            {
                if (!FileUtils.IsPreviewValid(inputQuizInfo.PreviewImage))
                {
                    return(BadRequest(Constants.InvalidImage));
                }

                quizInfoEntity.PreviewPath = await FileUtils.SaveAsync(DirType.Previews, inputQuizInfo.PreviewImage);
            }

            string queryParam = RandomGenerator.GenerateHexKey();

            quizInfoEntity.TemporaryLink = queryParam;

            quizInfoEntity.CreatedAt = DateTime.Now;

            if (quizInfoEntity.OwnerId == null)
            {
                return(BadRequest(Constants.OwnerNull));
            }

            /*Will be changed in the future accroding to User Identity */
            quizInfoEntity.Owner = manager.Repository <User>().FindBy(u => u.Id == quizInfoEntity.OwnerId).SingleOrDefault();

            string mongoId = RandomGenerator.GenerateHexKey();

            quizInfoEntity.QuizId = mongoId;

            await manager.Repository <QuizInfo>().Create(quizInfoEntity);

            manager.Save();

            mongoId = mongo.Create(mongoId);

            if (string.IsNullOrEmpty(mongoId))
            {
                return(BadRequest(Constants.MongoDbCreationFailure(nameof(Entities.Models.Mongo.Quiz))));
            }

            var result = mapper.Map <QuizInfoForOwnerDto>(quizInfoEntity);

            var request = HttpContext.Request;

            result.TemporaryLink = LinkUtils.GenerateTemporaryLink(request.IsHttps, request.Host.Value, request.Path, queryParam);

            // It will be changed according to the User Identity
            result.HasAccessToEdit = true;

            return(CreatedAtRoute("QuizInfoById", new { id = result.Id }, result));
        }
コード例 #2
0
        public async Task GivenCollectionNameAndRecord_WhenCreate_ThenCreateSuccessful()
        {
            //?Given
            var collectionName = "Survey";
            var record         = new SurveyEntity();

            SetupGetCollections(collectionName);

            _mockCollection.Setup(x => x.InsertOneAsync(record, null, It.IsAny <CancellationToken>()))
            .Verifiable();

            //?When
            await _mongoService.Create(collectionName, record);

            //?Then
            _mockDb.VerifyAll();
            _mockCollection.VerifyAll();
        }
コード例 #3
0
        public Task Create(User user)
        {
            var userEntity = _mapper.Map <UserEntity>(user);

            return(_mongoService.Create(_collectionName, userEntity));
        }
コード例 #4
0
        public Task Create(Product product)
        {
            var productEntity = _mapper.Map <ProductEntity>(product);

            return(_mogoService.Create(_collectionName, productEntity));
        }
コード例 #5
0
        public async Task Create(Survey survey)
        {
            var surveyEntiity = _mapper.Map <SurveyEntity>(survey);

            await _service.Create(_collectionName, surveyEntiity);
        }
コード例 #6
0
        public Task Create(Category category)
        {
            var categoryEntity = _mapper.Map <CategoryEntity>(category);

            return(_mongoService.Create(_collectionName, categoryEntity));
        }
コード例 #7
0
        public Task Create(Subscription subscription)
        {
            var subscritionEntity = _mapper.Map <SubscriptionEntity>(subscription);

            return(_mogoService.Create(_collectionName, subscritionEntity));
        }
コード例 #8
0
        public ActionResult <Book> Create(Book book)
        {
            _restApiService.Create(book);

            return(CreatedAtRoute("GetBook", new { id = book.Id.ToString() }, book));
        }
コード例 #9
0
        public async Task Create(AuthUser authUser)
        {
            var userEntity = _mapper.Map <AuthUserEntity>(authUser);

            await _mongoService.Create(_collectionName, userEntity);
        }
コード例 #10
0
        public async Task Create(Answer answer)
        {
            var answerEntity = _mapper.Map <AnswerEntity>(answer);

            await _service.Create(_collectionName, answerEntity);
        }
コード例 #11
0
        public async Task Create(Email email)
        {
            var emailEntity = _mapper.Map <EmailEntity>(email);

            await _service.Create(_collectionName, emailEntity);
        }