public async Task <IActionResult> Create(ConfiscationViewModel model) { if (ModelState.IsValid) { string uniqueFileName = UploadedFile(model); Confiscation data = new Confiscation { TrackingNo = model.TrackingNo, Jurisdiction = model.Jurisdiction, DateFiled = model.DateFiled, DocketCaseNo = model.DocketCaseNo, CaseTitleRespondent = model.CaseTitleRespondent, NatureOfViolation = model.NatureOfViolation, CourtFiled = model.CourtFiled, VehiclePlateNo = model.VehiclePlateNo, KindSpecies = model.KindSpecies, EstimatedValue = model.EstimatedValue, ForestProductStockPiled = model.ForestProductStockPiled, BoardFeet = model.BoardFeet, CubicMeter = model.CubicMeter, Status = model.Status, Remarks = model.Remarks, FilePath = uniqueFileName, }; _context.Add(data); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
// GET: Confiscations/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var model = await _context.Confiscation.FindAsync(id); ConfiscationViewModel vm = new ConfiscationViewModel { TrackingNo = model.TrackingNo, Jurisdiction = model.Jurisdiction, DateFiled = model.DateFiled, DocketCaseNo = model.DocketCaseNo, CaseTitleRespondent = model.CaseTitleRespondent, NatureOfViolation = model.NatureOfViolation, CourtFiled = model.CourtFiled, VehiclePlateNo = model.VehiclePlateNo, KindSpecies = model.KindSpecies, EstimatedValue = model.EstimatedValue, ForestProductStockPiled = model.ForestProductStockPiled, BoardFeet = model.BoardFeet, CubicMeter = model.CubicMeter, Status = model.Status, Remarks = model.Remarks, }; if (model == null) { return(NotFound()); } return(View(vm)); }
public async Task <IActionResult> Edit(int id, ConfiscationViewModel model) { if (id != model.Id) { return(NotFound()); } if (ModelState.IsValid) { try { string uniqueFileName = UploadedFile(model); Confiscation data = new Confiscation { Id = model.Id, TrackingNo = model.TrackingNo, Jurisdiction = model.Jurisdiction, DateFiled = model.DateFiled, DocketCaseNo = model.DocketCaseNo, CaseTitleRespondent = model.CaseTitleRespondent, NatureOfViolation = model.NatureOfViolation, CourtFiled = model.CourtFiled, VehiclePlateNo = model.VehiclePlateNo, KindSpecies = model.KindSpecies, EstimatedValue = model.EstimatedValue, ForestProductStockPiled = model.ForestProductStockPiled, BoardFeet = model.BoardFeet, CubicMeter = model.CubicMeter, Status = model.Status, Remarks = model.Remarks, FilePath = uniqueFileName, }; _context.Update(data); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ConfiscationExists(model.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(model)); }
private string UploadedFile(ConfiscationViewModel 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); }