Ejemplo n.º 1
0
        public async Task <IActionResult> Create(BookUploadPictureViewModel model)
        {
            // Remove user from model validation as it is not submitted in the form.
            // Validation will fail is this is not in here
            ModelState.Remove("UserId");


            var user = await GetCurrentUserAsync();

            if (ModelState.IsValid)
            {
                model.Book.User   = user;
                model.Book.UserId = user.Id;
                await UploadImage(model.ImageFile);

                model.Book.ImagePath = model.ImageFile.FileName;
                _context.Add(model.Book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookTypeId"] = new SelectList(_context.BookType, "BookTypeId", "Description", model.Book.BookTypeId);
            ViewData["UserId"]     = new SelectList(_context.ApplicationUsers, "Id", "Id", model.Book.UserId);
            return(View(model));
        }
Ejemplo n.º 2
0
        // GET: Books/Create
        public IActionResult Create()
        {
            BookUploadPictureViewModel model = new BookUploadPictureViewModel();

            model.Book             = new Book();
            ViewData["BookTypeId"] = new SelectList(_context.BookType, "BookTypeId", "Description");
            ViewData["UserId"]     = new SelectList(_context.ApplicationUsers, "Id", "Id");
            return(View(model));
        }