public async Task AddPlatformAsync(AddPlatformInputModel model, string rootPath) { await this.CheckIfPlatformExistsByNameAsync(model.Name); var developer = await this.developerRepository.All() .FirstOrDefaultAsync(x => x.Name == model.Developer); if (developer == null) { developer = new Developer() { Name = model.Developer, }; } var imagePath = await GlobalMethods.UploadedFile(model.Image, model.Name, rootPath, MainFilePath); var platform = new Platform() { Info = model.Info, ReleaseDate = model.ReleaseDate, Developer = developer, Image = imagePath, Name = model.Name, }; await this.platformRepository.AddAsync(platform); await this.platformRepository.SaveChangesAsync(); }
public async Task <IActionResult> Add(AddPlatformInputModel model) { var rootPath = this.environment.WebRootPath; if (!this.ModelState.IsValid) { return(this.View()); } await this.platformService.AddPlatformAsync(model, rootPath); return(this.RedirectToAction("Add")); }