Exemplo n.º 1
0
        public ActionResult AllowDownload(int id)
        {
            // get logged in user
            User user = _dbcontext.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();
            // get download object by id
            Download download = _dbcontext.Downloads.Find(id);

            // check if logged in user and note seller is same or not
            if (user.UserID == download.Seller)
            {
                // get sellernoteattachement object
                SellerNotesAttachment attachement = _dbcontext.SellerNotesAttachments.Where(x => x.NoteID == download.NoteID && x.IsActive == true).FirstOrDefault();

                // update data in download table
                _dbcontext.Downloads.Attach(download);
                download.AttaachementDownloadID     = DateTime.Now;
                download.IsSellerHasAllowedDownload = true;
                download.AttachementPath            = attachement.FilePath;
                download.ModifiedBy   = user.UserID;
                download.ModifiedDate = DateTime.Now;
                _dbcontext.SaveChanges();

                // send mail
                AllowDownloadTemplate(download, user);

                return(RedirectToAction("BuyerRequest"));
            }
            else
            {
                return(RedirectToAction("BuyerRequest"));
            }
        }
Exemplo n.º 2
0
        public ActionResult DeleteDraft(int id)
        {
            // get notes using id
            SellerNote note = _dbcontext.SellerNotes.Where(x => x.ID == id && x.IsActive == true).FirstOrDefault();

            // if note is not found
            if (note == null)
            {
                return(HttpNotFound());
            }
            // get attachement files using note id
            IEnumerable <SellerNotesAttachment> noteattachement = _dbcontext.SellerNotesAttachments.Where(x => x.NoteID == id && x.IsActive == true).ToList();

            // if noteattachement count is 0
            if (noteattachement.Count() == 0)
            {
                return(HttpNotFound());
            }
            // filepaths for note and note attachements
            string notefolderpath           = Server.MapPath("~/Members/" + note.SellerID + "/" + note.ID);
            string noteattachmentfolderpath = Server.MapPath("~/Members/" + note.SellerID + "/" + note.ID + "/Attachements");

            // get directory
            DirectoryInfo notefolder            = new DirectoryInfo(notefolderpath);
            DirectoryInfo attachementnotefolder = new DirectoryInfo(noteattachmentfolderpath);

            // empty directory
            EmptyFolder(attachementnotefolder);
            EmptyFolder(notefolder);
            // delete directory
            Directory.Delete(notefolderpath);

            // remove note from database
            _dbcontext.SellerNotes.Remove(note);

            // remove attachement from database
            foreach (var item in noteattachement)
            {
                SellerNotesAttachment attachement = _dbcontext.SellerNotesAttachments.Where(x => x.ID == item.ID).FirstOrDefault();
                _dbcontext.SellerNotesAttachments.Remove(attachement);
            }

            // save changes
            _dbcontext.SaveChanges();

            return(RedirectToAction("Dashboard"));
        }
Exemplo n.º 3
0
        public ActionResult EditNotes(int id)
        {
            // get logged in user
            User user = _dbcontext.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            // get note
            SellerNote note = _dbcontext.SellerNotes.Where(x => x.ID == id && x.IsActive == true && x.SellerID == user.UserID).FirstOrDefault();
            // get note attachement
            SellerNotesAttachment attachement = _dbcontext.SellerNotesAttachments.Where(x => x.NoteID == id).FirstOrDefault();

            if (note != null)
            {
                // create object of edit note viewmodel
                EditNotesViewModel viewModel = new EditNotesViewModel
                {
                    ID               = note.ID,
                    NoteID           = note.ID,
                    Title            = note.Title,
                    Category         = note.Category,
                    Picture          = note.DisplayPicture,
                    Note             = attachement.FilePath,
                    NumberofPages    = note.NumberOfPages,
                    Description      = note.Description,
                    NoteType         = note.NoteType,
                    UniversityName   = note.UniversityName,
                    Course           = note.Course,
                    CourseCode       = note.CourseCode,
                    Country          = note.Country,
                    Professor        = note.Professor,
                    IsPaid           = note.IsPaid,
                    SellingPrice     = note.SellingPrice,
                    Preview          = note.NotesPreview,
                    NoteCategoryList = _dbcontext.NoteCategories.Where(x => x.IsActive == true).ToList(),
                    NoteTypeList     = _dbcontext.NoteTypes.Where(x => x.IsActive == true).ToList(),
                    CountryList      = _dbcontext.Countries.Where(x => x.IsActive == true).ToList()
                };

                // return viewmodel to edit notes page
                return(View(viewModel));
            }
            else
            {
                // if note not found
                return(HttpNotFound());
            }
        }
Exemplo n.º 4
0
        public ActionResult EditNotes(int id, EditNotesViewModel notes)
        {
            // check if model state is valid or not
            if (ModelState.IsValid)
            {
                // get logged in user
                var user = _dbcontext.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();
                // get note
                var sellernotes = _dbcontext.SellerNotes.Where(x => x.ID == id && x.IsActive == true && x.SellerID == user.UserID).FirstOrDefault();
                // if sellernote null
                if (sellernotes == null)
                {
                    return(HttpNotFound());
                }
                // check if note is paid or preview is not null
                if (notes.IsPaid == true && notes.Preview == null && sellernotes.NotesPreview == null)
                {
                    ModelState.AddModelError("NotesPreview", "This field is required if selling type is paid");
                    return(View(notes));
                }
                // get note attachement
                var notesattachement = _dbcontext.SellerNotesAttachments.Where(x => x.NoteID == notes.NoteID && x.IsActive == true).ToList();

                // attache note object and update
                _dbcontext.SellerNotes.Attach(sellernotes);
                sellernotes.Title          = notes.Title.Trim();
                sellernotes.Category       = notes.Category;
                sellernotes.NoteType       = notes.NoteType;
                sellernotes.NumberOfPages  = notes.NumberofPages;
                sellernotes.Description    = notes.Description.Trim();
                sellernotes.Country        = notes.Country;
                sellernotes.UniversityName = notes.UniversityName.Trim();
                sellernotes.Course         = notes.Course.Trim();
                sellernotes.CourseCode     = notes.CourseCode.Trim();
                sellernotes.Professor      = notes.Professor.Trim();
                if (notes.IsPaid == true)
                {
                    sellernotes.IsPaid       = true;
                    sellernotes.SellingPrice = notes.SellingPrice;
                }
                else
                {
                    sellernotes.IsPaid       = false;
                    sellernotes.SellingPrice = 0;
                }
                sellernotes.ModifiedDate = DateTime.Now;
                sellernotes.ModifiedBy   = user.UserID;
                _dbcontext.SaveChanges();

                // if display picture is not null
                if (notes.DisplayPicture != null)
                {
                    // if note object has already previously uploaded picture then delete it
                    if (sellernotes.DisplayPicture != null)
                    {
                        string   path = Server.MapPath(sellernotes.DisplayPicture);
                        FileInfo file = new FileInfo(path);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                    }

                    // save updated profile picture in directory and save directory path in database
                    string displaypicturefilename = System.IO.Path.GetFileName(notes.DisplayPicture.FileName);
                    string displaypicturepath     = "~/Members/" + user.UserID + "/" + sellernotes.ID + "/";
                    CreateDirectoryIfMissing(displaypicturepath);
                    string displaypicturefilepath = Path.Combine(Server.MapPath(displaypicturepath), displaypicturefilename);
                    sellernotes.DisplayPicture = displaypicturepath + displaypicturefilename;
                    notes.DisplayPicture.SaveAs(displaypicturefilepath);
                }

                // if note preview is not null
                if (notes.NotesPreview != null)
                {
                    // if note object has already previously uploaded note preview then delete it
                    if (sellernotes.NotesPreview != null)
                    {
                        string   path = Server.MapPath(sellernotes.NotesPreview);
                        FileInfo file = new FileInfo(path);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                    }

                    // save updated note preview in directory and save directory path in database
                    string notespreviewfilename = System.IO.Path.GetFileName(notes.NotesPreview.FileName);
                    string notespreviewpath     = "~/Members/" + user.UserID + "/" + sellernotes.ID + "/";
                    CreateDirectoryIfMissing(notespreviewpath);
                    string notespreviewfilepath = Path.Combine(Server.MapPath(notespreviewpath), notespreviewfilename);
                    sellernotes.NotesPreview = notespreviewpath + notespreviewfilename;
                    notes.NotesPreview.SaveAs(notespreviewfilepath);
                }

                // check if user upload notes or not
                if (notes.UploadNotes[0] != null)
                {
                    // if user upload notes then delete directory that have previously uploaded notes
                    string        path = Server.MapPath(notesattachement[0].FilePath);
                    DirectoryInfo dir  = new DirectoryInfo(path);
                    EmptyFolder(dir);

                    // remove previously uploaded attachement from database
                    foreach (var item in notesattachement)
                    {
                        SellerNotesAttachment attachement = _dbcontext.SellerNotesAttachments.Where(x => x.ID == item.ID).FirstOrDefault();
                        _dbcontext.SellerNotesAttachments.Remove(attachement);
                    }

                    // add newly uploaded attachement in database and save it in database
                    foreach (HttpPostedFileBase file in notes.UploadNotes)
                    {
                        // check if file is null or not
                        if (file != null)
                        {
                            // save file in directory
                            string notesattachementfilename = System.IO.Path.GetFileName(file.FileName);
                            string notesattachementpath     = "~/Members/" + user.UserID + "/" + sellernotes.ID + "/Attachements/";
                            CreateDirectoryIfMissing(notesattachementpath);
                            string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename);
                            file.SaveAs(notesattachementfilepath);

                            // create object of sellernotesattachement
                            SellerNotesAttachment notesattachements = new SellerNotesAttachment
                            {
                                NoteID      = sellernotes.ID,
                                FileName    = notesattachementfilename,
                                FilePath    = notesattachementpath,
                                CreatedDate = DateTime.Now,
                                CreatedBy   = user.UserID,
                                IsActive    = true
                            };

                            // save seller notes attachement
                            _dbcontext.SellerNotesAttachments.Add(notesattachements);
                            _dbcontext.SaveChanges();
                        }
                    }
                }

                return(RedirectToAction("Dashboard", "SellYourNotes"));
            }
            else
            {
                return(RedirectToAction("EditNotes", new { id = notes.ID }));
            }
        }
Exemplo n.º 5
0
        public ActionResult AddNotes(AddNotesViewModel addnotesviewmodel)
        {
            // check if upload note is null or not
            if (addnotesviewmodel.UploadNotes[0] == null)
            {
                ModelState.AddModelError("UploadNotes", "This field is required");
                addnotesviewmodel.NoteCategoryList = _dbcontext.NoteCategories.Where(x => x.IsActive == true).ToList();
                addnotesviewmodel.NoteTypeList     = _dbcontext.NoteTypes.Where(x => x.IsActive == true).ToList();
                addnotesviewmodel.CountryList      = _dbcontext.Countries.Where(x => x.IsActive == true).ToList();
                return(View(addnotesviewmodel));
            }
            // check and raise error for note preview is null for paid notes
            if (addnotesviewmodel.IsPaid == true && addnotesviewmodel.NotesPreview == null)
            {
                ModelState.AddModelError("NotesPreview", "This field is required if selling type is paid");
                addnotesviewmodel.NoteCategoryList = _dbcontext.NoteCategories.Where(x => x.IsActive == true).ToList();
                addnotesviewmodel.NoteTypeList     = _dbcontext.NoteTypes.Where(x => x.IsActive == true).ToList();
                addnotesviewmodel.CountryList      = _dbcontext.Countries.Where(x => x.IsActive == true).ToList();
                return(View(addnotesviewmodel));
            }

            foreach (HttpPostedFileBase file in addnotesviewmodel.UploadNotes)
            {
                if (!System.IO.Path.GetExtension(file.FileName).Equals(".pdf"))
                {
                    ModelState.AddModelError("UploadNotes", "Only PDF Format is allowed");
                    addnotesviewmodel.NoteCategoryList = _dbcontext.NoteCategories.Where(x => x.IsActive == true).ToList();
                    addnotesviewmodel.NoteTypeList     = _dbcontext.NoteTypes.Where(x => x.IsActive == true).ToList();
                    addnotesviewmodel.CountryList      = _dbcontext.Countries.Where(x => x.IsActive == true).ToList();
                    return(View(addnotesviewmodel));
                }
            }


            // check model state
            if (ModelState.IsValid)
            {
                // create seller note object
                SellerNote sellernotes = new SellerNote();

                User user = _dbcontext.Users.FirstOrDefault(x => x.EmailID == User.Identity.Name);

                sellernotes.SellerID       = user.UserID;
                sellernotes.Title          = addnotesviewmodel.Title.Trim();
                sellernotes.Status         = _dbcontext.ReferenceDatas.Where(x => x.Value.ToLower() == "draft").Select(x => x.ID).FirstOrDefault();
                sellernotes.Category       = addnotesviewmodel.Category;
                sellernotes.NoteType       = addnotesviewmodel.NoteType;
                sellernotes.NumberOfPages  = addnotesviewmodel.NumberofPages;
                sellernotes.Description    = addnotesviewmodel.Description.Trim();
                sellernotes.UniversityName = addnotesviewmodel.UniversityName.Trim();
                sellernotes.Country        = addnotesviewmodel.Country;
                sellernotes.Course         = addnotesviewmodel.Course.Trim();
                sellernotes.CourseCode     = addnotesviewmodel.CourseCode.Trim();
                sellernotes.Professor      = addnotesviewmodel.Professor.Trim();
                sellernotes.IsPaid         = addnotesviewmodel.IsPaid;
                if (sellernotes.IsPaid)
                {
                    sellernotes.SellingPrice = addnotesviewmodel.SellingPrice;
                }
                else
                {
                    sellernotes.SellingPrice = 0;
                }
                sellernotes.CreatedDate = DateTime.Now;
                sellernotes.CreatedBy   = user.UserID;
                sellernotes.IsActive    = true;

                // add note in database and save
                _dbcontext.SellerNotes.Add(sellernotes);
                _dbcontext.SaveChanges();

                // get seller note
                sellernotes = _dbcontext.SellerNotes.Find(sellernotes.ID);

                // if display picture is not null then save picture into directory and directory path into database
                if (addnotesviewmodel.DisplayPicture != null)
                {
                    string displaypicturefilename = System.IO.Path.GetFileName(addnotesviewmodel.DisplayPicture.FileName);
                    string displaypicturepath     = "~/Members/" + user.UserID + "/" + sellernotes.ID + "/";
                    CreateDirectoryIfMissing(displaypicturepath);
                    string displaypicturefilepath = Path.Combine(Server.MapPath(displaypicturepath), displaypicturefilename);
                    sellernotes.DisplayPicture = displaypicturepath + displaypicturefilename;
                    addnotesviewmodel.DisplayPicture.SaveAs(displaypicturefilepath);
                }

                // if note preview is not null then save picture into directory and directory path into database
                if (addnotesviewmodel.NotesPreview != null)
                {
                    string notespreviewfilename = System.IO.Path.GetFileName(addnotesviewmodel.NotesPreview.FileName);
                    string notespreviewpath     = "~/Members/" + user.UserID + "/" + sellernotes.ID + "/";
                    CreateDirectoryIfMissing(notespreviewpath);
                    string notespreviewfilepath = Path.Combine(Server.MapPath(notespreviewpath), notespreviewfilename);
                    sellernotes.NotesPreview = notespreviewpath + notespreviewfilename;
                    addnotesviewmodel.NotesPreview.SaveAs(notespreviewfilepath);
                }

                // update note preview path and display picture path and save changes
                _dbcontext.SellerNotes.Attach(sellernotes);
                _dbcontext.Entry(sellernotes).Property(x => x.DisplayPicture).IsModified = true;
                _dbcontext.Entry(sellernotes).Property(x => x.NotesPreview).IsModified   = true;
                _dbcontext.SaveChanges();

                // attachement files
                foreach (HttpPostedFileBase file in addnotesviewmodel.UploadNotes)
                {
                    // check if file is null or not
                    if (file != null)
                    {
                        // save file in directory
                        string notesattachementfilename = System.IO.Path.GetFileName(file.FileName);
                        string notesattachementpath     = "~/Members/" + user.UserID + "/" + sellernotes.ID + "/Attachements/";
                        CreateDirectoryIfMissing(notesattachementpath);
                        string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename);
                        file.SaveAs(notesattachementfilepath);

                        // create object of sellernotesattachement
                        SellerNotesAttachment notesattachements = new SellerNotesAttachment
                        {
                            NoteID      = sellernotes.ID,
                            FileName    = notesattachementfilename,
                            FilePath    = notesattachementpath,
                            CreatedDate = DateTime.Now,
                            CreatedBy   = user.UserID,
                            IsActive    = true
                        };

                        // save seller notes attachement
                        _dbcontext.SellerNotesAttachments.Add(notesattachements);
                        _dbcontext.SaveChanges();
                    }
                }

                return(RedirectToAction("Dashboard", "SellYourNotes"));
            }
            // if model state is not valid
            else
            {
                // create object of addnotesviewmodel
                AddNotesViewModel viewModel = new AddNotesViewModel
                {
                    NoteCategoryList = _dbcontext.NoteCategories.Where(x => x.IsActive == true).ToList(),
                    NoteTypeList     = _dbcontext.NoteTypes.Where(x => x.IsActive == true).ToList(),
                    CountryList      = _dbcontext.Countries.Where(x => x.IsActive == true).ToList()
                };

                return(View(viewModel));
            }
        }
Exemplo n.º 6
0
        public ActionResult CloneNote(int noteid)
        {
            // get logged in user
            var user = _dbcontext.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            // get rejected note by id
            var rejectednote = _dbcontext.SellerNotes.Find(noteid);

            // create object of sellernote for create clone of note
            SellerNote clonenote = new SellerNote();

            clonenote.SellerID       = rejectednote.SellerID;
            clonenote.Status         = _dbcontext.ReferenceDatas.Where(x => x.Value.ToLower() == "draft").Select(x => x.ID).FirstOrDefault();
            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.UserID;
            clonenote.CreatedDate    = DateTime.Now;
            clonenote.IsActive       = true;

            // save note in database
            _dbcontext.SellerNotes.Add(clonenote);
            _dbcontext.SaveChanges();

            // get clonenote
            clonenote = _dbcontext.SellerNotes.Find(clonenote.ID);

            // if display picture is not null then copy file from rejected note's folder to clone note's new folder
            if (rejectednote.DisplayPicture != null)
            {
                var rejectednotefilepath = Server.MapPath(rejectednote.DisplayPicture);
                var clonenotefilepath    = "~/Members/" + user.UserID + "/" + 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));
                _dbcontext.SaveChanges();
            }

            // if note preview is not null then copy file from rejected note's folder to clone note's new folder
            if (rejectednote.NotesPreview != null)
            {
                var rejectednotefilepath = Server.MapPath(rejectednote.NotesPreview);
                var clonenotefilepath    = "~/Members/" + user.UserID + "/" + 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));
                _dbcontext.SaveChanges();
            }

            // attachment path of rejected note and clone note
            var rejectednoteattachement = Server.MapPath("~/Members/" + user.UserID + "/" + rejectednote.ID + "/Attachements/");
            var clonenoteattachement    = "~/Members/" + user.UserID + "/" + clonenote.ID + "/Attachements/";

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

            // create directory for attachement folder
            Directory.CreateDirectory(attachementfilepath);

            // get attachements files from rejected note and copy to clone note
            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())));
                }

                // save attachment in database
                SellerNotesAttachment attachement = new SellerNotesAttachment();
                attachement.NoteID      = clonenote.ID;
                attachement.FileName    = Path.GetFileName(file.ToString());
                attachement.FilePath    = clonenoteattachement;
                attachement.CreatedDate = DateTime.Now;
                attachement.CreatedBy   = user.UserID;
                attachement.IsActive    = true;

                _dbcontext.SellerNotesAttachments.Add(attachement);
                _dbcontext.SaveChanges();
            }
            return(RedirectToAction("Dashboard", "SellYourNotes"));
        }