Пример #1
0
        public async Task <IActionResult> Create(Cinema newCinema, IFormFile poster)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create", newCinema));
            }
            else
            {
                if (poster != null)
                {
                    newCinema.ImageMimeType = poster.ContentType;
                    newCinema.Poster        = new byte[poster.Length];
                    using (var binaryReader = new BinaryReader(poster.OpenReadStream()))
                    {
                        newCinema.Poster = binaryReader.ReadBytes((int)poster.Length);
                    }
                }
                newCinema.UserName = User.Identity.Name;
                await _context.AddAsync(newCinema);

                await _context.SaveChangesAsync();

                var cinema = await _context.FindCinemaByTitleAsync(newCinema.Name);

                return(RedirectToAction("Details", new { id = cinema.CinemaID, listName = "AllCinema" }));
            }
        }