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)); }
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(); }
public Task Create(User user) { var userEntity = _mapper.Map <UserEntity>(user); return(_mongoService.Create(_collectionName, userEntity)); }
public Task Create(Product product) { var productEntity = _mapper.Map <ProductEntity>(product); return(_mogoService.Create(_collectionName, productEntity)); }
public async Task Create(Survey survey) { var surveyEntiity = _mapper.Map <SurveyEntity>(survey); await _service.Create(_collectionName, surveyEntiity); }
public Task Create(Category category) { var categoryEntity = _mapper.Map <CategoryEntity>(category); return(_mongoService.Create(_collectionName, categoryEntity)); }
public Task Create(Subscription subscription) { var subscritionEntity = _mapper.Map <SubscriptionEntity>(subscription); return(_mogoService.Create(_collectionName, subscritionEntity)); }
public ActionResult <Book> Create(Book book) { _restApiService.Create(book); return(CreatedAtRoute("GetBook", new { id = book.Id.ToString() }, book)); }
public async Task Create(AuthUser authUser) { var userEntity = _mapper.Map <AuthUserEntity>(authUser); await _mongoService.Create(_collectionName, userEntity); }
public async Task Create(Answer answer) { var answerEntity = _mapper.Map <AnswerEntity>(answer); await _service.Create(_collectionName, answerEntity); }
public async Task Create(Email email) { var emailEntity = _mapper.Map <EmailEntity>(email); await _service.Create(_collectionName, emailEntity); }