public async Task <bool> Create(FactServiceModel factServiceModel) { Fact factus = new Fact() { Id = factServiceModel.Id, Content = factServiceModel.Content, PdfFile = factServiceModel.PdfFile, }; await context.Facts.AddAsync(factus); int result = await context.SaveChangesAsync(); return(result > 0); }
public async Task Create_WithCorrectData_ShouldSuccesfullyCreate() { string errorMessagePrefix = "FactsService Method CreateEvent() does not work properly."; var context = CDGBulgariaInmemoryFactory.InitializeContext(); this.factsService = new FactsService(context); FactServiceModel factus = new FactServiceModel() { Content = "There are not yet found medicines for this desease.", PdfFile = "src/pics/something/sofia.pdf" }; bool actualResult = await this.factsService.Create(factus); Assert.True(actualResult, errorMessagePrefix); }
public async Task <IActionResult> Create(FactCreateInputModel factCreateInputModel) { if (!this.ModelState.IsValid) { return(this.View(factCreateInputModel)); } string fileUrl = await this.cloudinaryService.UploadFile(factCreateInputModel.PdfFile, factCreateInputModel.Id.ToString()); FactServiceModel factServiceModel = new FactServiceModel() { Id = factCreateInputModel.Id, Content = factCreateInputModel.Content, PdfFile = fileUrl, }; await this.factsService.Create(factServiceModel); return(this.Redirect("/")); }