Exemplo n.º 1
0
        public ActionResult NotesDetail(int Id)
        {
            SellerNote             sellrnote = dbobj.SellerNotes.Find(Id);
            SellerNotesAttachement objsellernoteattachment = dbobj.SellerNotesAttachements.Where(x => x.NoteID == Id).FirstOrDefault();

            return(View(sellrnote));
        }
        public ActionResult Index(SellNote model, SellerNotesAttachement mod, FormCollection fc, HttpPostedFileBase imgfile, HttpPostedFileBase pdffile)
        {
            var data = _context.NoteTypes.ToList();

            ViewBag.NoteType = new SelectList(data, "Name", "Name");
            var item = _context.Countries.ToList();

            ViewBag.Country = new SelectList(item, "Name", "Name");
            var item1 = _context.NoteCatgories.ToList();

            ViewBag.Category = new SelectList(item1, "Name", "Name");

            if (ModelState.IsValid)
            {
                var currenttime = DateTime.UtcNow;
                if (imgfile != null)
                {
                    model.Display_pic = new byte[imgfile.ContentLength];
                    imgfile.InputStream.Read(model.Display_pic, 0, imgfile.ContentLength);
                }
                if (pdffile != null)
                {
                    String FileExt = Path.GetExtension(pdffile.FileName).ToUpper();
                    if (FileExt == ".PDF")
                    {
                        Stream       str     = pdffile.InputStream;
                        BinaryReader Br      = new BinaryReader(str);
                        Byte[]       FileDet = Br.ReadBytes((Int32)str.Length);
                        mod.FileName       = model.FileName = pdffile.FileName;
                        mod.FileContent    = model.Upload_note = FileDet;
                        mod.AttachmentSize = pdffile.ContentLength / 1024;
                    }
                }
                if (fc["save"] == "SAVE")
                {
                    model.Status = "Draft";
                }
                if (fc["publish"] == "PUBLISH")
                {
                    model.Status = " Submitted for Review";
                }
                var res = _context.Registers.Where(x => x.EmailId == User.Identity.Name).Single().Id;
                model.Seller_Id  = res;
                mod.CreatedBy    = model.CreatedBy = User.Identity.Name;
                mod.CreatedDate  = model.CreatedDate = currenttime;
                mod.ModifiedBy   = model.ModifiedBy = User.Identity.Name;
                mod.ModifiedDate = model.ModifiedDate = currenttime;
                mod.NoteTitle    = model.title;
                _context.SellerNotesAttachements.Add(mod);
                _context.SellNotes.Add(model);
                _context.SaveChanges();
                return(RedirectToAction("ViewNotes"));
            }
            else
            {
                return(View());
            }
        }
        public ActionResult PaymentRecieve(int id)
        {
            //Find Entry on Download Table
            Download download = db.Downloads.Find(id);

            //Auth User
            User user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);

            //in Download Note find Seller and Downloader
            var Downloader = db.Users.Where(x => x.ID == download.Downloader).FirstOrDefault();
            var Seller     = db.Users.Where(x => x.ID == download.Seller).FirstOrDefault();

            SellerNotesAttachement attachement = db.SellerNotesAttachements.Where(x => x.NoteID == download.NoteID).FirstOrDefault();

            //Make Change on Download Table
            db.Downloads.Attach(download);
            download.IsSellerHasAllowedDownload = true;
            download.AttachmentPath             = attachement.FilePath;
            download.AttachmentDownloadedDate   = DateTime.Now;
            download.ModifiedBy   = user.ID;
            download.ModifiedDate = DateTime.Now;
            db.SaveChanges();

            //Send Email to Buyer after Payment Recieve
            var body = "<p>Hello, {0}</p><br>" +
                       "<p>We would like to inform you that, {1} Allows you to download a note. Please login and see My Download tabs to download particular note.</p><br><br>" +
                       "<p>Regards</p>" +
                       "<p>Notes Marketplace</p>";

            var message = new MailMessage();

            message.To.Add(new MailAddress(Downloader.Email));                    // Reciever
            message.From       = new MailAddress("*****@*****.**"); // Sender
            message.Subject    = Seller.FirstName + " " + Seller.LastName + " " + "Allows you to download a note";
            message.Body       = string.Format(body, Downloader.FirstName + " " + Downloader.LastName, Seller.FirstName + " " + Seller.LastName);
            message.IsBodyHtml = true;

            using (var smtp = new SmtpClient())
            {
                var credential = new NetworkCredential
                {
                    UserName = "******",
                    Password = "******"
                };
                smtp.Credentials = credential;
                smtp.Host        = "smtp.gmail.com";
                smtp.Port        = 587;
                smtp.EnableSsl   = true;
                smtp.Send(message);
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult AllowDownload(int id, int buyerid)
        {
            //bool Status = false;
            {
                var v = dbobj.Downloads.Where(a => a.NoteId == id && a.isSellerhasAllowedDownloaded == false && a.downloader == buyerid).FirstOrDefault();
                SellerNotesAttachement sellernote    = dbobj.SellerNotesAttachements.Where(x => x.NoteID == id).FirstOrDefault();
                SellerNote             objsellernote = dbobj.SellerNotes.Where(x => x.Id == id).FirstOrDefault();
                if (v != null)
                {
                    v.isSellerhasAllowedDownloaded = true;
                    v.AttachmentPath = sellernote.FilePath;
                    v.ModifiedBy     = objsellernote.SellerID;
                    dbobj.SaveChanges();
                }

                User user = dbobj.Users.Where(x => x.ID == v.downloader).FirstOrDefault();
                SendEmailtoBuyer(user.EmailId.ToString(), v.NoteId);
            }
            return(RedirectToAction("Searchnote", "Notes"));
        }
Exemplo n.º 5
0
        public ActionResult Editnote(int?Id)
        {
            if (Id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SellerNote             sellrnote = dbobj.SellerNotes.Find(Id);
            SellerNotesAttachement objsellernoteattachment = dbobj.SellerNotesAttachements.Where(x => x.NoteID == Id).FirstOrDefault();
            UserSellernotes        editnote = new UserSellernotes
            {
                ID             = sellrnote.Id,
                Title          = sellrnote.Title,
                Category       = sellrnote.Category,
                Description    = sellrnote.Description,
                IsPaid         = sellrnote.IsPaid,
                NoteType       = sellrnote.NoteType,
                NumberofPages  = sellrnote.NumberofPages,
                UniversityName = sellrnote.UniversityName,
                Country        = sellrnote.Country,
                Course         = sellrnote.Course,
                CourseCode     = sellrnote.CourseCode,
                Professor      = sellrnote.Professor,
                SellingPrice   = sellrnote.SellingPrice,
                CreatedDate    = sellrnote.CreatedDate
            };

            if (sellrnote == null)
            {
                return(HttpNotFound());
            }

            ViewBag.NoteCategory = dbobj.NoteCategories.Where(x => x.isActive == true);
            ViewBag.NoteType     = dbobj.NoteTypes.Where(x => x.IsActive == true);
            ViewBag.Country      = dbobj.Countries.Where(x => x.isActive == true);
            return(View(editnote));
        }
        public ActionResult EditNote(EditNoteModel viewModel, string Command)
        {
            ViewBag.Class = "white-nav";
            User user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);

            var note = db.SellerNotes.Where(x => x.ID == viewModel.ID && x.Status == 1 && x.SellerID == user.ID).FirstOrDefault();

            var AttachFile = db.SellerNotesAttachements.Where(x => x.NoteID == note.ID).ToList();

            if (user != null && ModelState.IsValid)
            {
                note.Title          = viewModel.Title;
                note.Status         = Command == "Save" ? 1 : 2;
                note.Category       = viewModel.Category;
                note.NoteType       = viewModel.NoteType;
                note.NumberofPages  = viewModel.NumberofPages;
                note.Description    = viewModel.Description;
                note.UniversityName = viewModel.UniversityName;
                note.Country        = viewModel.Country;
                note.Course         = viewModel.Course;
                note.CourseCode     = viewModel.CourseCode;
                note.Professor      = viewModel.Professor;
                note.IsPaid         = viewModel.IsPaid;
                note.SellingPrice   = viewModel.SellingPrice;
                note.ModifiedDate   = DateTime.Now;

                db.Configuration.ValidateOnSaveEnabled = false;
                db.SaveChanges();


                if (viewModel.DisplayPicture != null)
                {
                    string   FileNameDelete = System.IO.Path.GetFileName(note.DisplayPicture);
                    string   PathImage      = Request.MapPath("~/Members/" + note.SellerID + "/" + note.ID + "/" + FileNameDelete);
                    FileInfo file           = new FileInfo(PathImage);
                    if (file.Exists)
                    {
                        file.Delete();
                    }
                    string displaypicturefilename = Path.GetFileName(viewModel.DisplayPicture.FileName);
                    string displaypicturepath     = "~/Members/" + note.SellerID + "/" + note.ID + "/";
                    string displaypicturefilepath = Path.Combine(Server.MapPath(displaypicturepath), displaypicturefilename);
                    note.DisplayPicture = displaypicturepath + displaypicturefilename;
                    viewModel.DisplayPicture.SaveAs(displaypicturefilepath);

                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                }

                if (viewModel.NotesPreview != null)
                {
                    string   FileNameDelete = System.IO.Path.GetFileName(note.NotesPreview);
                    string   PathPreview    = Request.MapPath("~/Members/" + note.SellerID + "/" + note.ID + "/" + FileNameDelete);
                    FileInfo file           = new FileInfo(PathPreview);
                    if (file.Exists)
                    {
                        file.Delete();
                    }
                    string notespreviewfilename = Path.GetFileName(viewModel.NotesPreview.FileName);
                    string notespreviewpath     = "~/Members/" + note.SellerID + "/" + note.ID + "/";
                    string notespreviewfilepath = Path.Combine(Server.MapPath(notespreviewpath), notespreviewfilename);
                    note.NotesPreview = notespreviewpath + notespreviewfilename;
                    viewModel.NotesPreview.SaveAs(notespreviewfilepath);

                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                }
                if (viewModel.UploadNotes != null)
                {
                    string deletepath = Request.MapPath("~/Members/" + note.SellerID + "/" + note.ID + "/Attachements/");
                    foreach (string filename in Directory.GetFiles(deletepath))
                    {
                        FileInfo file = new FileInfo(filename);
                        file.Delete();
                    }
                    foreach (var item in AttachFile)
                    {
                        db.SellerNotesAttachements.Remove(item);
                        db.SaveChanges();
                    }
                    foreach (HttpPostedFileBase file in viewModel.UploadNotes)
                    {
                        if (file != null)
                        {
                            string notesattachementfilename = System.IO.Path.GetFileName(file.FileName);
                            string notesattachementpath     = "~/Members/" + note.SellerID + "/" + note.ID + "/Attachements/";
                            string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename);

                            file.SaveAs(notesattachementfilepath);

                            SellerNotesAttachement notesattachements = new SellerNotesAttachement
                            {
                                NoteID       = viewModel.ID,
                                FileName     = notesattachementfilename,
                                FilePath     = notesattachementpath + notesattachementfilename,
                                CreatedDate  = DateTime.Now,
                                CreatedBy    = user.ID,
                                ModifiedDate = DateTime.Now,
                                ModifiedBy   = user.ID,
                                IsActive     = true
                            };

                            db.SellerNotesAttachements.Add(notesattachements);
                            db.SaveChanges();
                        }
                    }
                }
                return(RedirectToAction("Index", "SellNote"));
            }
            return(View());
        }
        public ActionResult AddNote(AddNoteModel note, string Command)
        {
            ViewBag.Class = "white-nav";
            User user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);

            if (user != null && ModelState.IsValid)
            {
                SellerNote sellernotes = new SellerNote();

                // Save note info in Database
                sellernotes.SellerID       = user.ID;
                sellernotes.Title          = note.Title;
                sellernotes.Status         = Command == "Save" ? 1 : 2;
                sellernotes.Category       = note.Category;
                sellernotes.NoteType       = note.NoteType;
                sellernotes.NumberofPages  = note.NumberofPages;
                sellernotes.Description    = note.Description;
                sellernotes.UniversityName = note.UniversityName;
                sellernotes.Country        = note.Country;
                sellernotes.Course         = note.Course;
                sellernotes.CourseCode     = note.CourseCode;
                sellernotes.Professor      = note.Professor;
                sellernotes.IsPaid         = note.IsPaid;
                sellernotes.SellingPrice   = sellernotes.IsPaid == false ? 0 : note.SellingPrice;
                sellernotes.CreatedDate    = DateTime.Now;
                sellernotes.ModifiedDate   = DateTime.Now;
                sellernotes.CreatedBy      = user.ID;
                sellernotes.ModifiedBy     = user.ID;
                sellernotes.IsActive       = true;

                // If seller add unvalid price
                if (note.IsPaid)
                {
                    if (note.SellingPrice == null || note.SellingPrice < 1)
                    {
                        ModelState.AddModelError("SellingPrice", "Enter valid Selling price");

                        AddNoteModel viewModel = GetDD();

                        return(View(viewModel));
                    }
                }
                if (note.UploadNotes[0] == null)
                {
                    ModelState.AddModelError("UploadNotes", "Enter Note");

                    AddNoteModel viewModel = GetDD();

                    return(View(viewModel));
                }

                db.SellerNotes.Add(sellernotes);
                db.SaveChanges();


                sellernotes = db.SellerNotes.Find(sellernotes.ID);

                //save note picture if User add
                if (note.DisplayPicture != null)
                {
                    string displaypicturefilename = Path.GetFileName(note.DisplayPicture.FileName);
                    string displaypicturepath     = "~/Members/" + user.ID + "/" + sellernotes.ID + "/";
                    CreateDirectoryIfMissing(displaypicturepath);
                    string displaypicturefilepath = Path.Combine(Server.MapPath("~/Members/" + user.ID + "/" + sellernotes.ID + "/"), displaypicturefilename);
                    sellernotes.DisplayPicture = displaypicturepath + displaypicturefilename;
                    note.DisplayPicture.SaveAs(displaypicturefilepath);
                }
                else
                {
                    var filepath = db.SystemConfigurations.Where(x => x.Name == "DefaultNoteDisplayPicture").FirstOrDefault();

                    sellernotes.DisplayPicture = filepath.Value;
                }


                //save note preview
                if (note.NotesPreview != null)
                {
                    string notespreviewfilename = System.IO.Path.GetFileName(note.NotesPreview.FileName);
                    string notespreviewpath     = "~/Members/" + user.ID + "/" + sellernotes.ID + "/";
                    CreateDirectoryIfMissing(notespreviewpath);
                    string notespreviewfilepath = Path.Combine(Server.MapPath(notespreviewpath), notespreviewfilename);
                    sellernotes.NotesPreview = notespreviewpath + notespreviewfilename;
                    note.NotesPreview.SaveAs(notespreviewfilepath);
                }

                db.SellerNotes.Attach(sellernotes);
                db.Entry(sellernotes).Property(x => x.DisplayPicture).IsModified = true;
                db.Entry(sellernotes).Property(x => x.NotesPreview).IsModified   = true;
                db.SaveChanges();

                //save note file
                if (note.UploadNotes[0] != null)
                {
                    foreach (HttpPostedFileBase file in note.UploadNotes)
                    {
                        if (file != null)
                        {
                            string notesattachementfilename = System.IO.Path.GetFileName(file.FileName);
                            string notesattachementpath     = "~/Members/" + user.ID + "/" + sellernotes.ID + "/Attachements/";
                            CreateDirectoryIfMissing(notesattachementpath);
                            string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename);

                            note.NotesPreview.SaveAs(notesattachementfilepath);


                            //save note file into SellerNotesAttachement table
                            SellerNotesAttachement notesattachements = new SellerNotesAttachement
                            {
                                NoteID       = sellernotes.ID,
                                FileName     = notesattachementfilename,
                                FilePath     = notesattachementpath + notesattachementfilename,
                                CreatedDate  = DateTime.Now,
                                CreatedBy    = user.ID,
                                ModifiedDate = DateTime.Now,
                                ModifiedBy   = user.ID,
                                IsActive     = true
                            };

                            db.SellerNotesAttachements.Add(notesattachements);

                            db.SaveChanges();
                        }
                    }
                }
                db.Dispose();

                return(RedirectToAction("Index", "SellNote"));
            }
            else
            {
                AddNoteModel viewModel = GetDD();
                return(View(viewModel));
            }
        }
Exemplo n.º 8
0
        public ActionResult Download(int Id)
        {
            SellerNote             sellrnote = dbobj.SellerNotes.Find(Id);
            SellerNotesAttachement objsellernoteattachment = dbobj.SellerNotesAttachements.Where(x => x.NoteID == Id).FirstOrDefault();
            NoteCategory           notecategory            = dbobj.NoteCategories.Where(x => x.Id == sellrnote.Category).FirstOrDefault();
            var  Emailid = User.Identity.Name.ToString();
            User user    = dbobj.Users.Where(x => x.EmailId == Emailid).FirstOrDefault();

            if (sellrnote.IsPaid == false)
            {
                Download download = new Download
                {
                    NoteId     = sellrnote.Id,
                    Seller     = sellrnote.SellerID,
                    downloader = user.ID,
                    isSellerhasAllowedDownloaded = true,
                    AttachmentPath           = objsellernoteattachment.FilePath,
                    IsAttachmentDownloaded   = true,
                    AttachmentDownloadedDate = DateTime.Now,
                    Ispaid         = sellrnote.IsPaid,
                    PurchasedPrice = sellrnote.SellingPrice,
                    NoteTitle      = sellrnote.Title,
                    NoteCategory   = notecategory.name,
                    Createddate    = DateTime.Now,
                    CreatedBy      = user.ID,
                    ModifiedBy     = user.ID,
                    isActive       = true
                };
                dbobj.Downloads.Add(download);
                dbobj.SaveChanges();
                using (ZipFile zip = new ZipFile())
                {
                    zip.AddDirectory(Server.MapPath("~/UploadFiles/" + sellrnote.SellerID + "/" + Id + "/" + "Attachments"));
                    MemoryStream output = new MemoryStream();
                    zip.Save(output);
                    return(File(output.ToArray(), "Attachments/zip", "Note.zip"));
                }
            }
            else
            {
                User objuser = dbobj.Users.Where(x => x.ID == sellrnote.SellerID).FirstOrDefault();
                SendEmailtoSeller(objuser.EmailId.ToString());
                Download download = new Download
                {
                    NoteId     = sellrnote.Id,
                    Seller     = sellrnote.SellerID,
                    downloader = user.ID,
                    isSellerhasAllowedDownloaded = false,
                    AttachmentDownloadedDate     = DateTime.Now,
                    Ispaid         = sellrnote.IsPaid,
                    PurchasedPrice = sellrnote.SellingPrice,
                    NoteTitle      = sellrnote.Title,
                    NoteCategory   = notecategory.name,
                    Createddate    = DateTime.Now,
                    CreatedBy      = user.ID,
                    ModifiedBy     = user.ID,
                    isActive       = true
                };
                dbobj.Downloads.Add(download);
                dbobj.SaveChanges();
            }
            return(RedirectToAction("Searchnote", "Notes"));
        }
Exemplo n.º 9
0
        public ActionResult addnotes(UserSellernotes note)
        {
            if (ModelState.IsValid)
            {
                var           Emailid       = User.Identity.Name.ToString();
                User          user          = dbobj.Users.Where(x => x.EmailId == Emailid).FirstOrDefault();
                Referencedata rf            = dbobj.Referencedatas.Where(x => x.RefCategory.ToLower() == "note status").FirstOrDefault();
                SellerNote    objsellernote = new SellerNote
                {
                    SellerID       = user.ID,
                    Status         = rf.Id,
                    Title          = note.Title,
                    Category       = note.Category,
                    NoteType       = note.NoteType,
                    Professor      = note.Professor,
                    Description    = note.Description,
                    IsPaid         = note.IsPaid,
                    NumberofPages  = note.NumberofPages,
                    UniversityName = note.UniversityName,
                    Country        = note.Country,
                    Course         = note.Course,
                    CourseCode     = note.CourseCode,
                    SellingPrice   = note.SellingPrice,
                    CreatedDate    = DateTime.Now,
                    IsActive       = true
                };
                dbobj.SellerNotes.Add(objsellernote);
                dbobj.SaveChanges();
                var noteID = objsellernote.Id;
                //display picture
                //generate path to store image
                string storepath = Path.Combine(Server.MapPath("/UploadFiles/" + user.ID), noteID.ToString());
                //check for directory, if not exist ,then create it
                if (!Directory.Exists(storepath))
                {
                    Directory.CreateDirectory(storepath);
                }
                if (note.DisplayPicture != null && note.DisplayPicture.ContentLength > 0)
                {
                    string _FileName = Path.GetFileNameWithoutExtension(note.DisplayPicture.FileName);
                    string extension = Path.GetExtension(note.DisplayPicture.FileName);
                    _FileName = "DP_" + DateTime.Now.ToString("yymmssfff") + extension;
                    string finalpath = Path.Combine(storepath, _FileName);
                    note.DisplayPicture.SaveAs(finalpath);
                    objsellernote.DisplayPicture = Path.Combine(("/UploadFiles/" + user.ID + "/" + noteID + "/"), _FileName);
                    dbobj.SaveChanges();
                }
                else
                {
                    objsellernote.DisplayPicture = "/System Configuration/DefaultImage/4.jpg";
                    dbobj.SaveChanges();
                }
                //upload notes
                string storeuploadpath = Path.Combine(storepath, "Attachments");
                //check for directory, if not exist ,then create it
                if (!Directory.Exists(storeuploadpath))
                {
                    Directory.CreateDirectory(storeuploadpath);
                }
                SellerNotesAttachement objsellernoteattachment = new SellerNotesAttachement
                {
                    NoteID      = noteID,
                    IsActive    = true,
                    CreatedBy   = user.ID,
                    Createddate = DateTime.Now
                };
                //
                int count = 1;
                var UploadnoteFilePath = "";
                var UploadnoteFileName = "";
                foreach (var File in note.UploadNotes)
                {
                    string _FileName = Path.GetFileNameWithoutExtension(File.FileName);
                    string extension = Path.GetExtension(File.FileName);
                    _FileName = "Attachment" + count + "_" + DateTime.Now.ToString("ddmyyyy") + extension;
                    string finalpath = Path.Combine(storeuploadpath, _FileName);
                    File.SaveAs(finalpath);
                    UploadnoteFileName += _FileName + ";";
                    UploadnoteFilePath += Path.Combine(("/UploadFiles/" + user.ID + "/" + noteID + "/Attachment/"), _FileName);
                    count++;
                }
                objsellernoteattachment.FileName = UploadnoteFileName;
                objsellernoteattachment.FilePath = UploadnoteFilePath;
                dbobj.SellerNotesAttachements.Add(objsellernoteattachment);
                dbobj.SaveChanges();
                //notes preview
                if (note.IsPaid == true)
                {
                    if (note.NotesPreview == null)
                    {
                        ViewBag.ErrorMessage = "plz upload preview";
                        ViewBag.NoteCategory = dbobj.NoteCategories.Where(x => x.isActive == true);
                        ViewBag.NoteType     = dbobj.NoteTypes.Where(x => x.IsActive == true);
                        ViewBag.Country      = dbobj.Countries.Where(x => x.isActive == true);
                        return(View(note));
                    }
                }

                if (note.NotesPreview != null && note.NotesPreview.ContentLength > 0)
                {
                    string _FileName = Path.GetFileNameWithoutExtension(note.NotesPreview.FileName);
                    string extension = Path.GetExtension(note.NotesPreview.FileName);
                    _FileName = "Preview_" + DateTime.Now.ToString("yymmssfff") + extension;
                    string finalpath = Path.Combine(storepath, _FileName);
                    note.NotesPreview.SaveAs(finalpath);
                    objsellernote.NotesPreview = Path.Combine(("/UploadFiles/" + user.ID + "/" + noteID + "/"), _FileName);
                    dbobj.SaveChanges();
                }
                return(RedirectToAction("Dashboard", "Notes"));
            }

            ViewBag.NoteCategory = dbobj.NoteCategories.Where(x => x.isActive == true);
            ViewBag.NoteType     = dbobj.NoteTypes.Where(x => x.IsActive == true);
            ViewBag.Country      = dbobj.Countries.Where(x => x.isActive == true);
            return(View(note));
        }
        public ActionResult CloneNote(int id)
        {
            var user = db.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault();

            var rejectednote = db.SellerNotes.Find(id);

            SellerNote clonenote = new SellerNote();

            clonenote.SellerID       = rejectednote.SellerID;
            clonenote.Status         = 1;
            clonenote.Title          = rejectednote.Title;
            clonenote.Category       = rejectednote.Category;
            clonenote.NoteType       = rejectednote.NoteType;
            clonenote.NumberofPages  = rejectednote.NumberofPages;
            clonenote.Description    = rejectednote.Description;
            clonenote.UniversityName = rejectednote.UniversityName;
            clonenote.Country        = rejectednote.Country;
            clonenote.Course         = rejectednote.Course;
            clonenote.CourseCode     = rejectednote.CourseCode;
            clonenote.Professor      = rejectednote.Professor;
            clonenote.IsPaid         = rejectednote.IsPaid;
            clonenote.SellingPrice   = rejectednote.SellingPrice;
            clonenote.CreatedBy      = user.ID;
            clonenote.CreatedDate    = DateTime.Now;
            clonenote.ModifiedBy     = user.ID;
            clonenote.ModifiedDate   = DateTime.Now;
            clonenote.IsActive       = true;

            db.SellerNotes.Add(clonenote);
            db.SaveChanges();

            clonenote = db.SellerNotes.Find(clonenote.ID);

            if (rejectednote.DisplayPicture != null)
            {
                var rejectednotefilepath = Server.MapPath(rejectednote.DisplayPicture);
                var clonenotefilepath    = "~/Members/" + user.ID + "/" + clonenote.ID + "/";

                var filepath = Path.Combine(Server.MapPath(clonenotefilepath));

                FileInfo file = new FileInfo(rejectednotefilepath);

                Directory.CreateDirectory(filepath);
                if (file.Exists)
                {
                    System.IO.File.Copy(rejectednotefilepath, Path.Combine(filepath, Path.GetFileName(rejectednotefilepath)));
                }

                clonenote.DisplayPicture = Path.Combine(clonenotefilepath, Path.GetFileName(rejectednotefilepath));
                db.SaveChanges();
            }

            if (rejectednote.NotesPreview != null)
            {
                var rejectednotefilepath = Server.MapPath(rejectednote.NotesPreview);
                var clonenotefilepath    = "~/Members/" + user.ID + "/" + clonenote.ID + "/";

                var filepath = Path.Combine(Server.MapPath(clonenotefilepath));

                FileInfo file = new FileInfo(rejectednotefilepath);

                Directory.CreateDirectory(filepath);

                if (file.Exists)
                {
                    System.IO.File.Copy(rejectednotefilepath, Path.Combine(filepath, Path.GetFileName(rejectednotefilepath)));
                }

                clonenote.NotesPreview = Path.Combine(clonenotefilepath, Path.GetFileName(rejectednotefilepath));
                db.SaveChanges();
            }

            var rejectednoteattachement = Server.MapPath("~/Members/" + user.ID + "/" + rejectednote.ID + "/Attachements/");
            var clonenoteattachement    = "~/Members/" + user.ID + "/" + clonenote.ID + "/Attachements/";

            var attachementfilepath = Path.Combine(Server.MapPath(clonenoteattachement));

            Directory.CreateDirectory(attachementfilepath);

            foreach (var files in Directory.GetFiles(rejectednoteattachement))
            {
                FileInfo file = new FileInfo(files);

                if (file.Exists)
                {
                    System.IO.File.Copy(file.ToString(), Path.Combine(attachementfilepath, Path.GetFileName(file.ToString())));
                }

                SellerNotesAttachement attachement = new SellerNotesAttachement();
                attachement.NoteID       = clonenote.ID;
                attachement.FileName     = Path.GetFileName(file.ToString());
                attachement.FilePath     = clonenoteattachement;
                attachement.CreatedDate  = DateTime.Now;
                attachement.CreatedBy    = user.ID;
                attachement.ModifiedDate = DateTime.Now;
                attachement.ModifiedBy   = user.ID;
                attachement.IsActive     = true;

                db.SellerNotesAttachements.Add(attachement);
                db.SaveChanges();
            }


            return(RedirectToAction("Index", "SellNote"));
        }
        public ActionResult Download(int Id)
        {
            SellerNote             sellrnote = dbobj.SellerNotes.Where(x => x.Id == Id && x.Referencedata.value == "published").FirstOrDefault();
            SellerNotesAttachement objsellernoteattachment = dbobj.SellerNotesAttachements.Where(x => x.NoteID == Id).FirstOrDefault();
            NoteCategory           notecategory            = dbobj.NoteCategories.Where(x => x.Id == sellrnote.Category).FirstOrDefault();
            var      Emailid = User.Identity.Name.ToString();
            User     user    = dbobj.Users.Where(x => x.EmailId == Emailid).FirstOrDefault();
            Download dwln    = dbobj.Downloads.Where(x => x.NoteId == Id && x.downloader == user.ID).FirstOrDefault();

            if (dwln != null)
            {
                dwln.ModifiedBy         = user.ID;
                dwln.ModifiedDate       = DateTime.Now;
                dbobj.Entry(dwln).State = EntityState.Modified;
                dbobj.SaveChanges();
            }

            else
            {
                if (sellrnote.IsPaid == false)
                {
                    Download download = new Download
                    {
                        NoteId     = sellrnote.Id,
                        Seller     = sellrnote.SellerID,
                        downloader = user.ID,
                        isSellerhasAllowedDownloaded = true,
                        AttachmentPath           = objsellernoteattachment.FilePath,
                        IsAttachmentDownloaded   = true,
                        AttachmentDownloadedDate = DateTime.Now,
                        Ispaid         = sellrnote.IsPaid,
                        PurchasedPrice = sellrnote.SellingPrice,
                        NoteTitle      = sellrnote.Title,
                        NoteCategory   = notecategory.name,
                        Createddate    = DateTime.Now,
                        CreatedBy      = user.ID,

                        isActive = true
                    };
                    dbobj.Downloads.Add(download);
                    dbobj.SaveChanges();
                    using (ZipFile zip = new ZipFile())
                    {
                        zip.AddDirectory(Server.MapPath("~/UploadFiles/" + sellrnote.SellerID + "/" + Id + "/" + "Attachments"));
                        MemoryStream output = new MemoryStream();
                        zip.Save(output);
                        return(File(output.ToArray(), "Attachments/zip", "Note.zip"));
                    }
                }

                else
                {
                    User objuser = dbobj.Users.Where(x => x.ID == sellrnote.SellerID).FirstOrDefault();
                    SystemConfiguration system  = dbobj.SystemConfigurations.Where(x => x.Key == "SupportEmail").FirstOrDefault();
                    SystemConfiguration system1 = dbobj.SystemConfigurations.Where(x => x.Key == "Password").FirstOrDefault();


                    SendEmailtoSeller(objuser.EmailId.ToString(), system.Value, system1.Value);
                    Download download = new Download
                    {
                        NoteId     = sellrnote.Id,
                        Seller     = sellrnote.SellerID,
                        downloader = user.ID,
                        isSellerhasAllowedDownloaded = false,
                        AttachmentDownloadedDate     = DateTime.Now,
                        Ispaid         = sellrnote.IsPaid,
                        PurchasedPrice = sellrnote.SellingPrice,
                        NoteTitle      = sellrnote.Title,
                        NoteCategory   = notecategory.name,
                        Createddate    = DateTime.Now,
                        CreatedBy      = user.ID,
                        ModifiedBy     = user.ID,
                        isActive       = true
                    };
                    dbobj.Downloads.Add(download);
                    dbobj.SaveChanges();
                }
            }
            return(RedirectToAction("Searchnote", "Notes"));
        }