예제 #1
0
        public async Task <IActionResult> Create([Bind("Id,Password,Email,Role")] Users users)
        {
            if (ModelState.IsValid)
            {
                _context.Add(users);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(users));
        }
예제 #2
0
        public async Task <IActionResult> Create(Books books, IFormFile Picture)
        {
            if (ModelState.IsValid)
            {
                if (Picture != null && Picture.Length > 0)
                {
                    byte[] imageData = null;
                    // Считывание переданного файла в массив байтов
                    using (var binaryReader = new BinaryReader(Picture.OpenReadStream()))
                    {
                        imageData = binaryReader.ReadBytes((int)Picture.Length);
                    }
                    // Установка массива байтов
                    books.Picture = imageData;
                }
                _context.Add(books);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(books));
        }