public ActionResult Create(FormGameViewModel model) { if (ModelState.IsValid) { Game Game = new Game() { Title = model.Title, Rules = model.Rules, Description = model.Description, NbMin = model.NbMin, NbMax = model.NbMax }; string UniqueTitle = null; if (model.CoverImage != null) { var PathFolder = Path.Combine(this.host.WebRootPath, "img", "game"); UniqueTitle = Guid.NewGuid().ToString() + "_" + model.CoverImage.FileName; var FilePath = Path.Combine(PathFolder, UniqueTitle); if (!Directory.Exists(PathFolder)) { Directory.CreateDirectory(PathFolder); } model.CoverImage.CopyTo(new FileStream(FilePath, FileMode.Create)); Game.CoverImage = UniqueTitle; } this.gameRepository.Create(Game); this.TempData["success"] = $"Le jeux {Game.Title} a bien été crée été"; return(RedirectToRoute("admin_games")); } return(View(model)); }
public IActionResult Update(FormGameViewModel model) { if (ModelState.IsValid) { Game Game = this.gameRepository.FindOneById(model.Id); if (Game != null) { string UniqueCoverImage = Guid.NewGuid().ToString() + "_" + model.CoverImage.FileName; var folderPath = Path.Combine(this.host.WebRootPath, "img", "game"); var PathFile = Path.Combine(folderPath, UniqueCoverImage); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } model.CoverImage.CopyTo(new FileStream(PathFile, FileMode.Create)); Game.Title = model.Title; Game.NbMin = model.NbMin; Game.NbMax = model.NbMax; Game.Rules = model.Rules; Game.Description = model.Description; Game.CoverImage = UniqueCoverImage; this.gameRepository.Update(Game); } return(RedirectToAction("Detail", new { Id = model.Id })); } return(View(model)); }
public IActionResult Edit(int Id) { Game Game = this.gameRepository.FindOneById(Id); if (Game != null) { FormGameViewModel model = new FormGameViewModel() { Id = Game.Id, Title = Game.Title, NbMax = Game.NbMax, NbMin = Game.NbMin, Description = Game.Description, Rules = Game.Rules }; this.ViewBag.Game = Game; return(View(model)); } return(BadRequest()); }
public ActionResult Create() { FormGameViewModel model = new FormGameViewModel(); return(View(model)); }