public async Task <IActionResult> Create([Bind("Id,Username")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Exemplo n.º 2
0
        //public async Task<IActionResult> Create(Blog blog, IFormFile picture)
        //{
        //    blog.PostedOn = DateTime.Now;

        //    if (ModelState.IsValid)
        //    {
        //        _context.Add(blog);
        //        await _context.SaveChangesAsync();
        //        return RedirectToAction(nameof(Index));
        //    }
        //    return View(blog);
        //}

        public async Task <IActionResult> Create(Blog blog, IFormFile ImageData)
        {
            blog.Image    = ConvertToBytes(ImageData);
            blog.PostedOn = DateTime.Now;

            if (ModelState.IsValid)
            {
                _context.Add(blog);
                await _context.SaveChangesAsync();

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