public void AddProjectAsyncShouldReturnProjectCorrectly() { var options = new DbContextOptionsBuilder <IntillegioContext>() .UseInMemoryDatabase(databaseName: "Add_Project_Db") .Options; var dbContext = new IntillegioContext(options); var projectBindingModel = new AdminProjectBindingModel { Name = "Venera Base", Image350X350 = "https://i.postimg.cc/PrSsz2qS/141222115103-cloud-city-horizontal-large-gallery.png" }; var mapper = new Mock <IMapper>(); mapper.Setup(m => m.Map <Project>(projectBindingModel)) .Returns(new Project { Name = "Venera Base", Image350X350 = "https://i.postimg.cc/PrSsz2qS/141222115103-cloud-city-horizontal-large-gallery.png" }); var mapping = mapper.Object; var service = new ProjectsService(dbContext, mapper.Object); service.AddProjectAsync(projectBindingModel); Assert.True(dbContext.Projects.Any(n => n.Name == projectBindingModel.Name)); Assert.True(dbContext.Projects.Any(b => b.Image350X350 == projectBindingModel.Image350X350)); }
public async Task <IActionResult> AddProject(AdminProjectBindingModel model) { if (!ModelState.IsValid) { return(View()); } await _projectsService.AddProjectAsync(model); return(RedirectToAction("ProjectsAdmin")); }
public async Task AddProjectAsync(AdminProjectBindingModel project) { var model = this.Mapper.Map <Project>(project); model.CategoryId = DbContext.Categories.FirstOrDefault(c => c.CategoryName == project.Category).Id; model.PartnerId = DbContext.Partners.FirstOrDefault(p => p.Name == project.Partner).Id; await DbContext.Projects.AddAsync(model); await DbContext.SaveChangesAsync(); }
public async Task <IActionResult> AddProjectPost(AdminProjectBindingModel model) { string pictureUrl1280X478 = await _cloudinaryService.UploadPictureAsync( model.Image1280X478, model.Name); string pictureUrl400X354 = await _cloudinaryService.UploadPictureAsync( model.Image400X354, model.Name); string pictureUrl450X398 = await _cloudinaryService.UploadPictureAsync( model.Image450X398, model.Name); string pictureUrl550X365 = await _cloudinaryService.UploadPictureAsync( model.Image550X365, model.Name); var project = new Project { About = model.About, Name = model.Name, Number = model.Number, Subname = model.Subname, Image1280X478 = pictureUrl1280X478, Image400X354 = pictureUrl400X354, Image450X398 = pictureUrl450X398, Image550X365 = pictureUrl550X365, }; await DbContext.Projects.AddAsync(project); await DbContext.SaveChangesAsync(); int id = project.Id; return(RedirectToAction("AddImagesInGallery")); }