public ActionResult ReturnSoldNote(int NoteID) { SellerNote notedetail = db.SellerNotes.Where(m => m.id == NoteID).SingleOrDefault(); var user = db.Users.Where(m => m.EmailID == System.Web.HttpContext.Current.User.Identity.Name).SingleOrDefault(); var attechment = db.SellerNotesAttechments.Where(m => m.NoteID == notedetail.id).SingleOrDefault(); if (user.id == notedetail.SellerID) { FileDownload obj = new FileDownload(); var ListOfFile = obj.GetFile(attechment.FilePath).ToList(); using (var memoryStream = new MemoryStream()) { using (var zipArchiv = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) { for (int i = 0; i < ListOfFile.Count(); i++) { zipArchiv.CreateEntryFromFile(ListOfFile[i].FilePath, ListOfFile[i].FileName); } } return(File(memoryStream.ToArray(), "application/zip", "Attachments.zip")); } } return(null); }
public ActionResult DownloadEvaluacionesFiles(string strNombreArchivos) { string message = string.Empty; try { FileDownload obj = new FileDownload(strNombreArchivos); var filesCol = obj.GetFile().ToList(); using (var memoryStream = new MemoryStream()) { using (var ziparchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) { for (int i = 0; i < filesCol.Count; i++) { ziparchive.CreateEntryFromFile(filesCol[i].FilePath, filesCol[i].FileName); } } //Elimino los archivos creado en TEMP for (int i = 0; i < filesCol.Count; i++) { string[] List = Directory.GetFiles(filesCol[i].FilePathOrigen, filesCol[i].FileName); foreach (string f in List) { System.IO.File.Delete(f); } } return(File(memoryStream.ToArray(), "application/zip", "Evaluaciones.zip")); } } catch (Exception ex) { message = "Error, favor volver a intentarlo"; Errores err = new Errores(); err.SetError(ex, "GetPeriodosCarreraDocente"); } return(null); }
public ActionResult DownloadAttechment(int NoteID) { SellerNote notedetail = db.SellerNotes.Where(m => m.id == NoteID).SingleOrDefault(); var user = db.Users.Where(m => m.EmailID == System.Web.HttpContext.Current.User.Identity.Name).SingleOrDefault(); var attechment = db.SellerNotesAttechments.Where(m => m.NoteID == notedetail.id).SingleOrDefault(); if (TempData.ContainsKey("returnFile")) { TempData.Remove("returnFile"); FileDownload obj = new FileDownload(); var ListOfFile = obj.GetFile(attechment.FilePath).ToList(); using (var memoryStream = new MemoryStream()) { using (var zipArchiv = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) { for (int i = 0; i < ListOfFile.Count(); i++) { zipArchiv.CreateEntryFromFile(ListOfFile[i].FilePath, ListOfFile[i].FileName); } } return(File(memoryStream.ToArray(), "application/zip", "Attachments.zip")); } } var alreadyDownloadedUser = db.Downloads.Where(m => m.NoteID == notedetail.id && m.Downloader == user.id && (m.IsPaid == false || (m.IsPaid == true && m.IsAttechmentDownloaded == true))).SingleOrDefault(); if (alreadyDownloadedUser != null) { alreadyDownloadedUser.ModifiedBy = user.id; alreadyDownloadedUser.ModifiedDate = DateTime.Now; db.Downloads.Attach(alreadyDownloadedUser); db.Entry(alreadyDownloadedUser).State = EntityState.Modified; db.SaveChanges(); FileDownload obj = new FileDownload(); var ListOfFile = obj.GetFile(attechment.FilePath).ToList(); using (var memoryStream = new MemoryStream()) { using (var zipArchiv = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) { for (int i = 0; i < ListOfFile.Count(); i++) { zipArchiv.CreateEntryFromFile(ListOfFile[i].FilePath, ListOfFile[i].FileName); } } return(File(memoryStream.ToArray(), "application/zip", "Attachments.zip")); } } var AllowedpaidUserForDownload = db.Downloads.Where(m => m.NoteID == notedetail.id && m.Downloader == user.id && m.IsPaid == true && m.IsAttechmentDownloaded == false && m.IsSellerHasAllowedDownload == true).SingleOrDefault(); if (AllowedpaidUserForDownload != null) { AllowedpaidUserForDownload.PurchasedPrice = notedetail.SellingPrice; AllowedpaidUserForDownload.AttechmentPath = attechment.FilePath; AllowedpaidUserForDownload.IsAttechmentDownloaded = true; AllowedpaidUserForDownload.AttechmentDownloadedDate = DateTime.Now; AllowedpaidUserForDownload.ModifiedBy = user.id; AllowedpaidUserForDownload.ModifiedDate = DateTime.Now; db.Downloads.Attach(AllowedpaidUserForDownload); db.Entry(AllowedpaidUserForDownload).State = EntityState.Modified; db.SaveChanges(); } TempData["Reload"] = NoteID; return(RedirectToAction("MyDonwloads", "User")); }