Beispiel #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));
        }
Beispiel #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();
        }
Beispiel #3
0
        public Task Create(User user)
        {
            var userEntity = _mapper.Map <UserEntity>(user);

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

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

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

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

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

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

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

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

            await _service.Create(_collectionName, emailEntity);
        }