public IActionResult UploadEditLetterCharts(string pageBaseId, int id, int letterChartsPageNumber) { Guid PageBaseId = Guid.Parse(pageBaseId); string message = ""; bool result = false; try { long size = 0; var files = Request.Form.Files; string ServerPath = ""; foreach (var file in files) { var filename = ContentDispositionHeaderValue .Parse(file.ContentDisposition) .FileName .Trim('"'); var editfilename = filename.Replace("zip", "htm"); ServerPath = "/pageletterchart/" + editfilename; filename = _webHostEnvironment.WebRootPath + "\\pageletterchart" + $@"\{filename}"; var filePath = _webHostEnvironment.WebRootPath + "\\pageletterchart"; size += file.Length; string startPath = filePath; string zipPath = filePath + "\\" + file.FileName; string extractPath = filePath; using (FileStream fs = System.IO.File.Create(filename)) { file.CopyTo(fs); fs.Flush(); } ZipFile.ExtractToDirectory(zipPath, extractPath, true); } LetterChart lC = _context.LetterCharts.Where(C => C.Id == id).FirstOrDefault(); lC.ServerPath = ServerPath; _context.LetterCharts.Update(lC); _context.SaveChanges(); result = true; } catch (Exception) { message = "عملیات ذخیره با شکست روبرو شد"; result = false; } return(Json(new { result = result, message = message })); }
// GET: Letter public LetterController() { chart = new LetterChart(); chart2 = new LetterChart2(); letterRepository = new EfLetterRepository(); }