コード例 #1
0
        // GET: VendorCategories/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            //instantiate view model for image uploader
            EditImageVCViewModel evm = new EditImageVCViewModel();

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

            evm.vendorCategory = await _context.VendorCatergories.FindAsync(id);

            if (evm.vendorCategory == null)
            {
                return(NotFound());
            }
            return(View(evm));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, EditImageVCViewModel evm)
        {
            if (id != evm.vendorCategory.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                // check to see if image file exists
                if (evm.ImageFile != null)
                {
                    // convert image into byte array
                    using (var memoryStream = new MemoryStream())
                    {
                        await evm.ImageFile.CopyToAsync(memoryStream);

                        evm.vendorCategory.CategoryImage = memoryStream.ToArray();
                    }
                }
                ;
                try
                {
                    _context.Update(evm.vendorCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VendorCategoryExists(evm.vendorCategory.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(evm));
        }