Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,SeriesID,ActorID,CharacterID,FirstAppereance,LastAppereance")] Casts casts)
        {
            if (id != casts.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(casts);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CastsExists(casts.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ActorID"]     = new SelectList(_context.Actors, "ID", "ID", casts.ActorID);
            ViewData["CharacterID"] = new SelectList(_context.Characters, "ID", "ID", casts.CharacterID);
            return(View(casts));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, IFormFile Photo, [Bind("ID,Name,Photo,Birthdate,Info")] Actors actors)
        {
            if (id != actors.ID)
            {
                return(NotFound());
            }
            if (Photo != null && Photo.Length > 0)
            {
                if (actors.Photo != null)
                {
                    var PhotoPath = _env.WebRootPath + actors.Photo;
                    if (System.IO.File.Exists(PhotoPath))
                    {
                        System.IO.File.Delete(PhotoPath);
                    }
                }
                var imagePath  = @"\Upload\Images\Actors\";
                var uploadPath = _env.WebRootPath + imagePath;

                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                var uniqFileName = Guid.NewGuid().ToString();
                var filename     = Path.GetFileName(uniqFileName + "." + Photo.FileName.Split(".")[1].ToLower());

                string fullPath = uploadPath + filename;

                imagePath = imagePath + @"\";

                var filePath = Path.Combine(imagePath, filename);
                using (var fileStream = new FileStream(fullPath, FileMode.Create))
                {
                    await Photo.CopyToAsync(fileStream);
                }
                actors.Photo = filePath;
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(actors);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ActorsExists(actors.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(actors));
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, IFormFile Photo, [Bind("ID,Name,Gender,Photo,Birthyear,Status,Info,SeriesID")] Characters characters)
        {
            if (id != characters.ID)
            {
                return(NotFound());
            }
            if (Photo != null && Photo.Length > 0)
            {
                if (characters.Photo != null)
                {
                    var PhotoPath = _env.WebRootPath + characters.Photo;
                    if (System.IO.File.Exists(PhotoPath))
                    {
                        System.IO.File.Delete(PhotoPath);
                    }
                }
                var imagePath  = @"\Upload\Images\Characters\";
                var uploadPath = _env.WebRootPath + imagePath;

                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                var uniqFileName = Guid.NewGuid().ToString();
                var filename     = Path.GetFileName(uniqFileName + "." + Photo.FileName.Split(".")[1].ToLower());

                string fullPath = uploadPath + filename;

                imagePath = imagePath + @"\";

                var filePath = Path.Combine(imagePath, filename);
                using (var fileStream = new FileStream(fullPath, FileMode.Create))
                {
                    await Photo.CopyToAsync(fileStream);
                }
                characters.Photo = filePath;
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(characters);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CharactersExists(characters.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index", "Characters", new { seriesID = characters.SeriesID }));
                //return RedirectToAction(nameof(Index));
            }
            ViewData["SeriesID"] = new SelectList(_context.Series, "ID", "Name", characters.SeriesID);
            return(RedirectToAction("Index", "Characters", new { seriesID = characters.SeriesID }));
            //return View(characters);
        }
Пример #4
0
        public async Task <IActionResult> Edit(int id, IFormFile Poster, IFormFile BackImage, [Bind("ID,Name,Poster,Premiere,IsEnded,BackImage,MainColor,SecondColor,Info")] Series series)
        {
            if (id != series.ID)
            {
                return(NotFound());
            }

            if (Poster != null && Poster.Length > 0)
            {
                if (series.Poster != null)
                {
                    var PhotoPath = _env.WebRootPath + series.Poster;
                    if (System.IO.File.Exists(PhotoPath))
                    {
                        System.IO.File.Delete(PhotoPath);
                    }
                }
                var imagePath  = @"\Upload\Images\Series\Posters\";
                var uploadPath = _env.WebRootPath + imagePath;

                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                var uniqFileName = Guid.NewGuid().ToString();
                var filename     = Path.GetFileName(uniqFileName + "." + Poster.FileName.Split(".")[1].ToLower());

                string fullPath = uploadPath + filename;

                imagePath = imagePath + @"\";

                var filePath = Path.Combine(imagePath, filename);
                using (var fileStream = new FileStream(fullPath, FileMode.Create))
                {
                    await Poster.CopyToAsync(fileStream);
                }
                series.Poster = filePath;
            }
            if (BackImage != null && BackImage.Length > 0)
            {
                if (series.BackImage != null)
                {
                    var PhotoPath = _env.WebRootPath + series.BackImage;
                    if (System.IO.File.Exists(PhotoPath))
                    {
                        System.IO.File.Delete(PhotoPath);
                    }
                }
                var imagePath  = @"\Upload\Images\Series\BackImages\";
                var uploadPath = _env.WebRootPath + imagePath;

                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                var uniqFileName = Guid.NewGuid().ToString();
                var filename     = Path.GetFileName(uniqFileName + "." + BackImage.FileName.Split(".")[1].ToLower());

                string fullPath = uploadPath + filename;

                imagePath = imagePath + @"\";

                var filePath = Path.Combine(imagePath, filename);
                using (var fileStream = new FileStream(fullPath, FileMode.Create))
                {
                    await BackImage.CopyToAsync(fileStream);
                }
                series.BackImage = filePath;
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(series);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SeriesExists(series.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(series));
        }