public ActionResult Edit() { GlavnaModel glavna = null; try { glavna = GlavnaDAO.GetGlavnaByIdADMIN(Convert.ToInt32(HttpContext.Session.GetInt32("ApprovalGlavnaID"))); glavna.InternePoruke = InternaPorukaDAO.GetMessagesById(glavna.AutoID); HttpContext.Session.SetInt32("ApprovalGlavnaMasterID", glavna.GlavnaMaster.AutoID); HttpContext.Session.SetString("ApprovalFilePath", Path.Combine(IocContainer.Configuration["DocumentsPath"], glavna.DatumKreiranjaUTC.Value.Year.ToString(), GetMonth(glavna.DatumKreiranjaUTC.Value), glavna.GlavnaMaster.AutoID.ToString(), glavna.AutoID.ToString())); //glavna.VrstaHomologacije.AtributSet = VrsteHomologacijeDAO.GetAtributSet(glavna.VrstaHomologacije.Id); GlavnaDAO.UpdateGlavnaApproval(Convert.ToInt32(HttpContext.Session.GetInt32("ApprovalGlavnaID")), HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik")); } catch (Exception) { } if (HttpContext.Session.GetObjectFromJson <KorisnikModel>("LogovaniKorisnik") == null) { return(View("~/Views/Login/Index.cshtml")); } HttpContext.Session.Remove("FileNameViewer"); return(View("Edit", glavna)); }
public async Task <IActionResult> DownloadFiles() { try { var glavna = GlavnaDAO.GetGlavnaByIdADMIN(Convert.ToInt32(Convert.ToInt32(HttpContext.Session.GetInt32("ApprovalGlavnaID")))); var filesPath = Path.Combine(IocContainer.Configuration["DocumentsPath"], glavna.DatumKreiranjaUTC.Value.Year.ToString(), GetMonth(glavna.DatumKreiranjaUTC.Value), glavna.GlavnaMaster.AutoID.ToString(), glavna.AutoID.ToString()); var result = Path.Combine(Path.Combine(IocContainer.Configuration["DocumentsPath"], glavna.DatumKreiranjaUTC.Value.Year.ToString(), GetMonth(glavna.DatumKreiranjaUTC.Value).ToString(), glavna.GlavnaMaster.AutoID.ToString(), glavna.AutoID.ToString() + ".zip")); if (System.IO.File.Exists(result)) { System.IO.File.Delete(result); } if (Directory.Exists(filesPath)) { ZipFile.CreateFromDirectory(filesPath, Path.Combine(filesPath, result)); FileInfo file = new FileInfo(result); var memory = new MemoryStream(); using (var stream = new FileStream(result, FileMode.Open)) { await stream.CopyToAsync(memory); } memory.Position = 0; HttpContext.Response.Headers.Add("Cache-Control", "no-cache, no-store, must-revalidate"); HttpContext.Response.Headers.Add("Pragma", "no-cache"); HttpContext.Response.Headers.Add("Expires", "0"); return(File(memory, GetContentType(result), Path.GetFileName(result))); } ViewBag.Message = "Nema unešenih dokumenata."; return(RedirectToAction("Edit")); } catch (Exception) { return(RedirectToAction("Edit"));; } }