//GET: AdminDownloadNote public ActionResult adminDownloadNote(int id) { using (NMEntities DBobj = new NMEntities()) { SellerNoteAttachment sellerAttachement = DBobj.SellerNoteAttachment.Where(x => x.NoteID == id).FirstOrDefault(); //Return files var filesPath = sellerAttachement.FilePath.Split(';'); var filesName = sellerAttachement.FileName.Split(';'); using (var ms = new MemoryStream()) { using (var z = new ZipArchive(ms, ZipArchiveMode.Create, true)) { foreach (var FilePath in filesPath) { string FullPath = Path.Combine(Server.MapPath(FilePath)); string FileName = Path.GetFileName(FullPath); if (FileName == "adminDownloadNote") { continue; } else { z.CreateEntryFromFile(FullPath, FileName); } } } return(File(ms.ToArray(), "application/zip", "Attachement.zip")); } } }
public ActionResult deactivateUser(int uid) { using (NMEntities nm = new NMEntities()) { Users udetail = nm.Users.Where(x => x.UserID == uid).FirstOrDefault(); IQueryable <NoteDetails> ndetail = nm.NoteDetails.Where(x => x.SellerID == uid); foreach (var i in ndetail) { i.IsActive = false; SellerNoteAttachment nddetails = nm.SellerNoteAttachment.Where(x => x.NoteID == i.NoteID).FirstOrDefault(); nddetails.IsActive = false; } udetail.IsActive = false; nm.SaveChanges(); return(View("members", "Admin")); } }
public ActionResult addNote(addnote notedetails) { try { if (ModelState.IsValid) { if (notedetails.SellType == "Paid" && notedetails.PreviewUpload == null) { NotesMarketPlaceEntities nm = new NotesMarketPlaceEntities(); ViewBag.previewmessage = "Note Preview Is Required For Paid Note..."; var notecategory = nm.Categories.ToList(); var notetype = nm.Type.ToList(); var country = nm.Country.ToList(); ViewBag.notecategoies = new SelectList(notecategory, "CategoryID", "CategoryName"); ViewBag.notetypes = new SelectList(notetype, "TypeID", "TypeName"); ViewBag.countries = new SelectList(country, "CountryID", "CountryName"); return(View()); } using (NotesMarketPlaceEntities nm = new NotesMarketPlaceEntities()) { Notes nd = new Notes(); SellerNoteAttachment sna = new SellerNoteAttachment(); nd.SellerID = (int)Session["UserID"]; nd.NotesTitle = notedetails.NoteTitle; nd.NotesCategory = notedetails.NoteCategoryID; nd.NotesType = notedetails.NoteTypeID; nd.UniversityInformation = notedetails.UniversityInformation; nd.Country = notedetails.CountryID; nd.CourseName = notedetails.Course; nd.CourseCode = notedetails.CourseCode; nd.Professor = notedetails.ProfessorName; nd.SellType = notedetails.SellType; nd.SellPrice = notedetails.SellPrice; nd.NoOfPages = notedetails.NumberOfPages; nd.Description = notedetails.NoteDescription; nd.Status = 4; nd.CreatedDate = DateTime.Now; nd.IsActive = true; nm.Notes.Add(nd); nm.SaveChanges(); string path = Path.Combine(Server.MapPath("~/Member/" + Session["UserID"].ToString()), nd.NoteID.ToString()); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (notedetails.DisplayPicture != null && notedetails.DisplayPicture.ContentLength > 0) { string fileName = Path.GetFileNameWithoutExtension(notedetails.DisplayPicture.FileName); string extension = Path.GetExtension(notedetails.DisplayPicture.FileName); fileName = "DP_" + DateTime.Now.ToString("ddMMyyyy") + extension; string finalpath = Path.Combine(path, fileName); notedetails.DisplayPicture.SaveAs(finalpath); nd.NotesDp = Path.Combine(("~/Member/" + Session["UserID"].ToString() + "/" + nd.NoteID.ToString() + "/"), fileName); nm.SaveChanges(); } if (notedetails.PreviewUpload != null && notedetails.PreviewUpload.ContentLength > 0) { string fileName = Path.GetFileNameWithoutExtension(notedetails.PreviewUpload.FileName); string extension = Path.GetExtension(notedetails.PreviewUpload.FileName); fileName = "PREVIEW_" + DateTime.Now.ToString("ddMMyyyy") + extension; string finalpath = Path.Combine(path, fileName); notedetails.PreviewUpload.SaveAs(finalpath); nd.PreviewUpload = Path.Combine(("~/Member/" + Session["UserID"].ToString() + "/" + nd.NoteID.ToString() + "/"), fileName); nm.SaveChanges(); } string attachmentpath = Path.Combine(Server.MapPath("~/Member/" + Session["UserID"].ToString() + "/" + nd.NoteID.ToString()), "attachment"); if (!Directory.Exists(attachmentpath)) { Directory.CreateDirectory(attachmentpath); } if (notedetails.NotesAttachment != null && notedetails.NotesAttachment[0].ContentLength > 0) { var count = 1; var FilePath = ""; var FileName = ""; foreach (var file in notedetails.NotesAttachment) { string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extension = Path.GetExtension(file.FileName); fileName = "Attachment_" + count + "_" + DateTime.Now.ToString("ddMMyyyy") + extension; string finalpath = Path.Combine(attachmentpath, fileName); file.SaveAs(finalpath); FileName += fileName + ";"; FilePath += Path.Combine(("~/Member/" + Session["UserID"].ToString() + "/" + nd.NoteID.ToString() + "/"), fileName) + ";"; count++; } sna.FileName = FileName; sna.FilePath = FilePath; sna.NoteID = nd.NoteID; sna.IsActive = true; sna.CreatedDate = DateTime.Now; sna.CreatedBy = (int)Session["UserID"]; nm.SaveChanges(); } nm.SellerNoteAttachment.Add(sna); nm.SaveChanges(); } } ModelState.Clear(); return(RedirectToAction("addNote", "User")); } catch (DbEntityValidationException e) { Console.WriteLine(e); } return(View()); }