Exemplo n.º 1
0
        public async Task <IActionResult> Create(BiosViewModel model)
        {
            var file = model.file; // Extracting the property file of IFormFile type

            //Upload the file using our new function/method
            string fileName = UploadFile(model.file);

            /*
             * We just finished writing the file and getting the BIO form values.
             * Let's go ahead and populate the imageUpload Property and give it the name of the file.
             */
            model.bio.ImageUpload = fileName;

            // Finally:  Write out data to our table.
            _context.Bios.Add(model.bio);
            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        // GET: Bios/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var bio = await _context.Bios.SingleOrDefaultAsync(m => m.Id == id);

            if (bio == null)
            {
                return(NotFound());
            }

            //Change the model that the view is expecting
            BiosViewModel model = new BiosViewModel();

            model.bio = bio;

            return(View(model));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, BiosViewModel model)
        {
            if (id != model.bio.Id)
            {
                return(NotFound());
            }

            //if (ModelState.IsValid)
            //{
            try
            {
                /*
                 * Upload the file using our new function/method
                 */
                string fileName = UploadFile(model.file); //Upload the file
                model.bio.ImageUpload = fileName;         //Upload the name of the file
                _context.Update(model.bio);

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BioExists(model.bio.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(RedirectToAction(nameof(Index)));

            //}
            return(View(model.bio));
        }