示例#1
0
        public IActionResult New(UpcomingGameViewModel vm, [FromServices] IWebHostEnvironment env)
        {
            if (ModelState.IsValid)
            {
                string fileName = null;
                if (vm.Photo != null && vm.Photo.Length > 0)
                {
                    fileName = vm.Photo.GenerateFileName();
                    var savePath = Path.Combine(env.WebRootPath, "img", fileName);
                    using FileStream fs = new FileStream(savePath, FileMode.Create);
                    vm.Photo.CopyTo(fs);
                }

                var upcomingGame = new UpcomingGames()
                {
                    Title     = vm.Title,
                    Time      = vm.Time,
                    PhotoPath = fileName,
                    Platform  = vm.Platform
                };

                _db.UpcomingGames.Add(upcomingGame);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View());
        }
示例#2
0
        public IActionResult Edit(int id)
        {
            UpcomingGames upcomingGames = _db.UpcomingGames.Find(id);

            if (upcomingGames == null)
            {
                return(NotFound());
            }

            var vm = new EditUpcomingGameViewModel()
            {
                Id        = upcomingGames.Id,
                Title     = upcomingGames.Title,
                PhotoPath = upcomingGames.PhotoPath,
                Platform  = upcomingGames.Platform,
                Time      = upcomingGames.Time
            };

            return(View(vm));
        }