// GET: DonatedConfiscateds/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var model = await _context.DonatedConfiscateds.FindAsync(id);

            DonatedConfiscatedViewModel vm = new DonatedConfiscatedViewModel
            {
                TrackingNo           = model.TrackingNo,
                DateOfDonation       = model.DateOfDonation,
                DoneeRecipient       = model.DoneeRecipient,
                SpeciesForm          = model.SpeciesForm,
                NumberOfPieces       = model.NumberOfPieces,
                VolumeBoardFeet      = model.VolumeBoardFeet,
                EstimatedMarketValue = model.EstimatedMarketValue,
                Purpose = model.Purpose,
            };

            if (model == null)
            {
                return(NotFound());
            }
            return(View(vm));
        }
        private string UploadedFile(DonatedConfiscatedViewModel model)
        {
            string uniqueFileName = null;

            if (model.FilePath != null)
            {
                string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "uploads");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.FilePath.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.FilePath.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
        public async Task <IActionResult> Edit(int id, DonatedConfiscatedViewModel model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    string             uniqueFileName = UploadedFile(model);
                    DonatedConfiscated data           = new DonatedConfiscated
                    {
                        Id                   = model.Id,
                        TrackingNo           = model.TrackingNo,
                        DateOfDonation       = model.DateOfDonation,
                        DoneeRecipient       = model.DoneeRecipient,
                        SpeciesForm          = model.SpeciesForm,
                        NumberOfPieces       = model.NumberOfPieces,
                        VolumeBoardFeet      = model.VolumeBoardFeet,
                        EstimatedMarketValue = model.EstimatedMarketValue,
                        Purpose              = model.Purpose,
                        FilePath             = uniqueFileName,
                    };
                    _context.Update(data);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DonatedConfiscatedExists(model.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
        public async Task <IActionResult> Create(DonatedConfiscatedViewModel model)
        {
            if (ModelState.IsValid)
            {
                string             uniqueFileName = UploadedFile(model);
                DonatedConfiscated data           = new DonatedConfiscated
                {
                    TrackingNo           = model.TrackingNo,
                    DateOfDonation       = model.DateOfDonation,
                    DoneeRecipient       = model.DoneeRecipient,
                    SpeciesForm          = model.SpeciesForm,
                    NumberOfPieces       = model.NumberOfPieces,
                    VolumeBoardFeet      = model.VolumeBoardFeet,
                    EstimatedMarketValue = model.EstimatedMarketValue,
                    Purpose  = model.Purpose,
                    FilePath = uniqueFileName,
                };
                _context.Add(data);
                await _context.SaveChangesAsync();

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