コード例 #1
0
        public ActionResult NoteDetails_Admin(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            SellerNotes sellerNote = objNotesEntities.SellerNotes.Find(id);


            if (sellerNote == null)
            {
                return(HttpNotFound());
            }
            Country                 country    = objNotesEntities.Country.Find(sellerNote.Country);
            NoteCategories          category   = objNotesEntities.NoteCategories.Find(sellerNote.NoteCategory);
            SellerNotesAttachements attechment = objNotesEntities.SellerNotesAttachements.Where(x => x.NoteID == sellerNote.ID).FirstOrDefault();

            if (country == null)
            {
                ViewBag.Country = null;
            }
            else
            {
                ViewBag.Country = country.CountryName;
            }
            var data = objNotesEntities.SellerNotes.Where(x => x.ID == id).FirstOrDefault();

            ViewBag.dispic    = data.DisplayPicture;
            ViewBag.notepre   = data.PreviewUpload;
            ViewBag.Category  = category.CategoryName;
            ViewBag.Attchment = attechment.FilePath;

            return(View(data));
        }
コード例 #2
0
        public ActionResult AllowDownload(int id)
        {
            Users user = context.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            Downloads download = context.Downloads.Find(id);

            if (user.ID == download.Seller)
            {
                SellerNotesAttachements attachement = context.SellerNotesAttachements.Where(x => x.NoteID == download.NoteID && x.IsActive == true).FirstOrDefault();


                context.Downloads.Attach(download);
                download.IsSellerHasAllowedDownload = true;
                download.AttachmentPath             = attachement.FilePath;
                download.ModifiedBy   = user.ID;
                download.ModifiedDate = DateTime.Now;
                context.SaveChanges();


                SendMailForAllowDownload(download, user);

                return(RedirectToAction("BuyerRequest"));
            }
            else
            {
                return(RedirectToAction("BuyerRequest"));
            }
        }
コード例 #3
0
        public ActionResult DeleteBook(int noteid)
        {
            SellerNotesAttachements attachment = dbobj.SellerNotesAttachements.Where(x => x.NoteID == noteid).FirstOrDefault();
            SellerNotes             noteobj    = dbobj.SellerNotes.Where(x => x.ID == noteid).FirstOrDefault();

            string mappedPath = Server.MapPath("/Members/" + noteobj.SellerID + "/" + noteid);

            Directory.Delete(mappedPath, true);

            dbobj.SellerNotesAttachements.Remove(attachment);
            dbobj.SellerNotes.Remove(noteobj);
            dbobj.SaveChanges();

            return(RedirectToAction("Dashboard"));
        }
コード例 #4
0
        public ActionResult EditNotes(int id)
        {
            // get current user
            Users user = context.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            // get sellernotes table details
            SellerNotes note = context.SellerNotes.Where(x => x.ID == id && x.IsActive == true && x.SellerID == user.ID).FirstOrDefault();
            // get noteattachement table details
            SellerNotesAttachements attachement = context.SellerNotesAttachements.Where(x => x.NoteID == id).FirstOrDefault();

            if (note != null)
            {
                // create object of edit note viewmodel
                EditNotesViewModel Model = 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 = context.NoteCategories.Where(x => x.IsActive == true).ToList(),
                    NoteTypeList     = context.NoteTypes.Where(x => x.IsActive == true).ToList(),
                    CountryList      = context.Countries.Where(x => x.IsActive == true).ToList()
                };

                // return viewmodel to edit notes page
                return(View(Model));
            }
            else
            {
                // if note not found
                return(HttpNotFound());
            }
        }
コード例 #5
0
        // [Route("SellYourNotes/DeleteDraft/{id}")]
        public ActionResult DeleteDraft(int id)
        {
            SellerNotes note = context.SellerNotes.Where(x => x.ID == id && x.IsActive == true).FirstOrDefault();

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

            IEnumerable <SellerNotesAttachements> attachement = context.SellerNotesAttachements.Where(x => x.NoteID == id && x.IsActive == true).ToList();

            if (attachement.Count() == 0)
            {
                return(HttpNotFound());
            }

            string notefolderpath           = Server.MapPath("~/Members/" + note.SellerID + "/" + note.ID);
            string noteattachmentfolderpath = Server.MapPath("~/Members/" + note.SellerID + "/" + note.ID + "/Attachements");


            DirectoryInfo folder            = new DirectoryInfo(notefolderpath);
            DirectoryInfo attachementfolder = new DirectoryInfo(noteattachmentfolderpath);

            //This Methods defines below
            DeleteDirectory(attachementfolder);
            DeleteDirectory(folder);

            Directory.Delete(notefolderpath);

            //Delete Data From Database Also
            context.SellerNotes.Remove(note);


            foreach (var item in attachement)
            {
                SellerNotesAttachements noteattachement = context.SellerNotesAttachements.Where(x => x.ID == item.ID).FirstOrDefault();
                context.SellerNotesAttachements.Remove(noteattachement);
            }


            context.SaveChanges();

            return(RedirectToAction("Dashboard"));
        }
コード例 #6
0
        public ActionResult CloneNote(int noteid)
        {
            var user = db.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault();

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

            SellerNotes clonenote = new SellerNotes();

            clonenote.SellerID       = rejectednote.SellerID;
            clonenote.Status         = 6;
            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.IsActive       = true;

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

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

            //Note image
            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)
                {
                    //copy the file from reject note and save in clone
                    System.IO.File.Copy(rejectednotefilepath, Path.Combine(filepath, Path.GetFileName(rejectednotefilepath)));
                }

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

            //Note preview
            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)
                {
                    //copy note review from rejected note and save in clone
                    System.IO.File.Copy(rejectednotefilepath, Path.Combine(filepath, Path.GetFileName(rejectednotefilepath)));
                }

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

            //upload notes
            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);

            //copy all files from reject and save again
            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())));
                }

                //add data in attachment folder
                SellerNotesAttachements attachement = new SellerNotesAttachements();
                attachement.NoteID      = clonenote.ID;
                attachement.FileName    = Path.GetFileName(file.ToString());
                attachement.FilePath    = clonenoteattachement;
                attachement.CreatedDate = DateTime.Now;
                attachement.CreatedBy   = user.ID;
                attachement.IsActive    = true;

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

            return(RedirectToAction("Dashboard", "SellNotes"));
        }
コード例 #7
0
        public ActionResult CloneNote(int noteid)
        {
            // get logged in user
            var user = context.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

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

            // create object of sellernotes table for create clone of note
            SellerNotes clonenote = new SellerNotes();

            clonenote.SellerID       = rejectednote.SellerID;
            clonenote.Status         = context.ReferenceData.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.ID;
            clonenote.CreatedDate    = DateTime.Now;
            clonenote.IsActive       = true;

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

            // get clonenote
            clonenote = context.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.ID + "/" + clonenote.ID + "/";

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

                FileInfo file = new FileInfo(rejectednotefilepath);


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

                clonenote.DisplayPicture = Path.Combine(clonenotefilepath, Path.GetFileName(rejectednotefilepath));
                context.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.ID + "/" + clonenote.ID + "/";

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

                FileInfo file = new FileInfo(rejectednotefilepath);



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

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

            // copy attachment path of rejected note to clone note
            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));

            // 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
                SellerNotesAttachements attachement = new SellerNotesAttachements();
                attachement.NoteID      = clonenote.ID;
                attachement.FileName    = Path.GetFileName(file.ToString());
                attachement.FilePath    = clonenoteattachement;
                attachement.CreatedDate = DateTime.Now;
                attachement.CreatedBy   = user.ID;
                attachement.IsActive    = true;

                context.SellerNotesAttachements.Add(attachement);
                context.SaveChanges();
            }
            return(RedirectToAction("Dashboard", "SellYourNotes"));
        }
コード例 #8
0
        public ActionResult AddNotes(AddNotesViewModel xyz)
        {
            if (ModelState.IsValid)
            {
                // create seller note object
                SellerNotes abc = new SellerNotes();


                var user = Context.Users.FirstOrDefault(x => x.Email == User.Identity.Name);
                abc.Status   = Context.ReferenceData.Where(x => x.Value.ToLower() == "Draft").Select(x => x.ID).FirstOrDefault();
                abc.SellerID = user.UserId;
                abc.Title    = xyz.Title.Trim();

                abc.Category       = xyz.Category;
                abc.NoteType       = xyz.NoteType;
                abc.NumberofPages  = xyz.NumberofPages;
                abc.Description    = xyz.Description.Trim();
                abc.UniversityName = xyz.UniversityName.Trim();
                abc.Country        = xyz.Country;
                abc.Course         = xyz.Course.Trim();
                abc.CourseCode     = xyz.CourseCode.Trim();
                abc.Professor      = xyz.Professor.Trim();
                abc.IsPaid         = xyz.IsPaid;
                if (abc.IsPaid)
                {
                    abc.SellingPrice = xyz.SellingPrice;
                }
                else
                {
                    abc.SellingPrice = 0;
                }

                abc.IsActive = true;
                Context.SellerNotes.Add(abc);


                Context.SaveChanges();



                //


                // add note in database and save



                // get seller note
                abc = Context.SellerNotes.Find(abc.ID);

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

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

                // update note preview path and display picture path and save changes
                //Context.SellerNotes.Add(abc);
                //Context.Entry(abc).Property(x => x.DisplayPicture).IsModified = true;
                //Context.Entry(abc).Property(x => x.NotesPreview).IsModified = true;

                Context.SaveChanges();



                // attachement files
                foreach (HttpPostedFileBase file in xyz.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 + "/" + abc.ID + "/Attachements/";
                        CreateDirectoryIfMissing(notesattachementpath);
                        string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename);
                        file.SaveAs(notesattachementfilepath);

                        // create object of sellernotesattachement
                        SellerNotesAttachements notesattachements = new SellerNotesAttachements
                        {
                            NotesID  = abc.ID,
                            FileName = notesattachementfilename,
                            FilePath = notesattachementpath,

                            IsActive = true
                        };

                        // save seller notes attachement
                        Context.SellerNotesAttachements.Add(notesattachements);



                        Context.SaveChanges();
                    }
                }
                return(RedirectToAction("Addnotes", "Addnotes"));
            }
            // if model state is not valid
            else
            {
                // create object of xyz
                AddNotesViewModel viewModel = new AddNotesViewModel
                {
                    NoteCategoryList = Context.NoteCategories.ToList(),
                    NoteTypeList     = Context.NoteTypes.ToList(),
                    CountryList      = Context.Countries.ToList()
                };

                return(View(viewModel));
            }
        }
コード例 #9
0
        public ActionResult EditNote(EditNoteViewModel editnote, string Command)
        {
            ViewBag.Class = "white-nav";

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

            var note = db.SellerNotes.Where(x => x.ID == editnote.ID && x.Status == 6 && x.SellerID == user.ID && x.IsActive == true).FirstOrDefault();

            var AttachFile = db.SellerNotesAttachements.Where(x => x.NoteID == note.ID && x.IsActive == true);

            if (user != null && ModelState.IsValid)
            {
                note.Title          = editnote.Title;
                note.Status         = Command == "Save" ? 6 : 7;
                note.Category       = editnote.Category;
                note.NoteType       = editnote.NoteType;
                note.NumberofPages  = editnote.NumberofPages;
                note.Description    = editnote.Description;
                note.UniversityName = editnote.UniversityName;
                note.Country        = editnote.Country;
                note.Course         = editnote.Course;
                note.CourseCode     = editnote.CourseCode;
                note.Professor      = editnote.Professor;
                note.IsPaid         = editnote.IsPaid;
                note.SellingPrice   = editnote.IsPaid == false ? 0 : note.SellingPrice;
                note.ModifiedDate   = DateTime.Now;
                note.ModifiedBy     = user.ID;

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

                if (editnote.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(editnote.DisplayPicture.FileName);
                    string displaypicturepath     = "~/Members/" + note.SellerID + "/" + note.ID + "/";
                    string displaypicturefilepath = Path.Combine(Server.MapPath(displaypicturepath), displaypicturefilename);
                    note.DisplayPicture = displaypicturepath + displaypicturefilename;
                    editnote.DisplayPicture.SaveAs(displaypicturefilepath);

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

                if (editnote.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(editnote.NotesPreview.FileName);
                    string notespreviewpath     = "~/Members/" + note.SellerID + "/" + note.ID + "/";
                    string notespreviewfilepath = Path.Combine(Server.MapPath(notespreviewpath), notespreviewfilename);
                    note.NotesPreview = notespreviewpath + notespreviewfilename;
                    editnote.NotesPreview.SaveAs(notespreviewfilepath);

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

                //bcoz its have multiple files
                if (editnote.UploadNotes[0] != null)
                {
                    string deletepath = Request.MapPath("~/Members/" + note.SellerID + "/" + note.ID + "/Attachements/");

                    //delete files
                    foreach (string filename in Directory.GetFiles(deletepath))
                    {
                        FileInfo file = new FileInfo(filename);
                        file.Delete();
                    }

                    //delete record by isactive false
                    foreach (var item in AttachFile)
                    {
                        item.IsActive = false;
                    }
                    db.SaveChanges();

                    //upload files in database
                    foreach (var newFiles in editnote.UploadNotes)
                    {
                        if (newFiles != null)
                        {
                            string notesattachementfilename = System.IO.Path.GetFileName(newFiles.FileName);
                            string notesattachementpath     = "~/Members/" + note.SellerID + "/" + note.ID + "/Attachements/";
                            string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename);
                            newFiles.SaveAs(notesattachementfilepath);

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

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

                return(RedirectToAction("Dashboard", "SellNotes"));
            }

            var category = db.NoteCategories.Where(x => x.IsActive == true).ToList();
            var type     = db.NoteTypes.Where(x => x.IsActive == true).ToList();
            var country  = db.Countries.Where(x => x.IsActive == true).ToList();

            editnote.NoteCategoryList = category;
            editnote.NoteTypeList     = type;
            editnote.CountryList      = country;

            return(View(editnote));
        }
コード例 #10
0
        public ActionResult AddNotes(AddNotesViewModel note, string Command)
        {
            ViewBag.navclass  = "white-nav";
            ViewBag.SellNotes = "active";

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

            //check user enter the profile details or not
            bool temp = db.UserProfile.Any(x => x.UserID == user.ID);

            if (!temp)
            {
                return(RedirectToAction("MyProfile", "UserProfile"));
            }

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

                sellernotes.SellerID       = user.ID;
                sellernotes.ActionedBy     = user.ID;
                sellernotes.Title          = note.Title;
                sellernotes.Status         = Command == "Save" ? 6 : 7; //6 for draft & 7 for submit for review
                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.CreatedBy      = user.ID;
                sellernotes.IsActive       = true;

                if (sellernotes.IsPaid)
                {
                    if (sellernotes.SellingPrice == null || sellernotes.SellingPrice < 1)
                    {
                        ModelState.AddModelError("SellingPrice", "Enter valid Selling price");
                        AddNotesViewModel viewModel = GetData();
                        return(View(viewModel));
                    }
                }

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

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

                if (note.DisplayPicture == null)
                {
                    //get default file name
                    string defaultFilename = Directory.GetFiles(Server.MapPath("~/Content/image/default-note-img/")).FirstOrDefault();
                    string finalfilename   = System.IO.Path.GetFileName(defaultFilename);

                    //defalt path if path is null
                    string userprofilepath = "~/Content/image/default-note-img/";
                    sellernotes.DisplayPicture = userprofilepath + finalfilename; //store path
                }

                if (note.DisplayPicture != null)
                {
                    string displaypicturefilename = System.IO.Path.GetFileName(note.DisplayPicture.FileName); //get filename
                    string displaypicturepath     = "~/Members/" + user.ID + "/" + sellernotes.ID + "/";      //path for save file
                    CreateDirectoryIfMissing(displaypicturepath);
                    string displaypicturefilepath = Path.Combine(Server.MapPath(displaypicturepath), displaypicturefilename);
                    sellernotes.DisplayPicture = displaypicturepath + displaypicturefilename;
                    note.DisplayPicture.SaveAs(displaypicturefilepath);
                }

                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();

                //uploaded multiple files
                string notesattachementpath = "~/Members/" + user.ID + "/" + sellernotes.ID + "/Attachements/";
                CreateDirectoryIfMissing(notesattachementpath);

                foreach (var file in note.UploadNotes)
                {
                    string notesattachementfilename = System.IO.Path.GetFileName(file.FileName);
                    string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename);
                    file.SaveAs(notesattachementfilepath);

                    SellerNotesAttachements notesattachements = new SellerNotesAttachements
                    {
                        NoteID      = sellernotes.ID,
                        FileName    = notesattachementfilename,
                        FilePath    = notesattachementpath,
                        CreatedDate = DateTime.Now,
                        CreatedBy   = user.ID,
                        IsActive    = true
                    };

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

                db.Dispose();
                return(RedirectToAction("AddNotes", "SellNotes"));
            }
            else
            {
                if (note.IsPaid)
                {
                    if (note.SellingPrice == null)
                    {
                        ModelState.AddModelError("SellingPrice", "Selling price is required");
                    }
                }
                AddNotesViewModel viewModel = GetData();
                return(View(viewModel));
            }
        }
コード例 #11
0
        public ActionResult EditNotes(int id, EditNotesViewModel notes)
        {
            // check if model state is valid or not
            if (ModelState.IsValid)
            {
                // get current user
                var user = context.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();
                // get Seller notes table
                var sellernotes = context.SellerNotes.Where(x => x.ID == id && x.IsActive == true && x.SellerID == user.ID).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 = context.SellerNotesAttachements.Where(x => x.NoteID == notes.NoteID && x.IsActive == true).ToList();

                // attache seller note object and update
                context.SellerNotes.Attach(sellernotes);
                sellernotes.Title          = notes.Title;
                sellernotes.Category       = notes.Category;
                sellernotes.NoteType       = notes.NoteType;
                sellernotes.NumberofPages  = notes.NumberofPages;
                sellernotes.Description    = notes.Description;
                sellernotes.Country        = notes.Country;
                sellernotes.UniversityName = notes.UniversityName;
                sellernotes.Course         = notes.Course;
                sellernotes.CourseCode     = notes.CourseCode;
                sellernotes.Professor      = notes.Professor;
                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.ID;
                context.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.ID + "/" + 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.ID + "/" + sellernotes.ID + "/";

                    CreateDirectoryIfMissing(notespreviewpath);

                    string notespreviewfilepath = Path.Combine(Server.MapPath(notespreviewpath), notespreviewfilename);
                    sellernotes.NotesPreview = notespreviewpath + notespreviewfilename;
                    notes.NotesPreview.SaveAs(notespreviewfilepath);
                }

                // check if seller 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);
                    DeleteDirectory(dir);

                    // remove previously uploaded attachement from database
                    foreach (var item in notesattachement)
                    {
                        SellerNotesAttachements attachement = context.SellerNotesAttachements.Where(x => x.ID == item.ID).FirstOrDefault();
                        context.SellerNotesAttachements.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.ID + "/" + sellernotes.ID + "/Attachements/";
                            CreateDirectoryIfMissing(notesattachementpath);
                            string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename);
                            file.SaveAs(notesattachementfilepath);

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

                            // save seller notes attachement
                            context.SellerNotesAttachements.Add(notesattachements);
                            context.SaveChanges();
                        }
                    }
                }

                return(RedirectToAction("Dashboard", "SellYourNotes"));
            }
            else
            {
                return(RedirectToAction("EditNotes", new { id = notes.ID }));
            }
        }
コード例 #12
0
        public ActionResult AddNotes(AddNotesViewModel addnotesmodel)
        {
            // check if upload note is null or not
            if (addnotesmodel.UploadNotes[0] == null)
            {
                ModelState.AddModelError("UploadNotes", "This field is required");
                return(View(addnotesmodel));
            }
            // check and raise error when note preview is null for paid notes
            if (addnotesmodel.IsPaid == true && addnotesmodel.NotesPreview == null)
            {
                ModelState.AddModelError("NotesPreview", "This field is required if selling type is paid");
                return(View(addnotesmodel));
            }
            // check model state
            if (ModelState.IsValid)
            {
                // create seller note object
                SellerNotes sellernotes = new SellerNotes();

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

                sellernotes.SellerID       = user.ID;
                sellernotes.Title          = addnotesmodel.Title;
                sellernotes.Status         = 6;
                sellernotes.Category       = addnotesmodel.Category;
                sellernotes.NoteType       = addnotesmodel.NoteType;
                sellernotes.NumberofPages  = addnotesmodel.NumberofPages;
                sellernotes.Description    = addnotesmodel.Description;
                sellernotes.UniversityName = addnotesmodel.UniversityName;
                sellernotes.Country        = addnotesmodel.Country;
                sellernotes.Course         = addnotesmodel.Course;
                sellernotes.CourseCode     = addnotesmodel.CourseCode;
                sellernotes.Professor      = addnotesmodel.Professor;
                sellernotes.IsPaid         = addnotesmodel.IsPaid;
                if (sellernotes.IsPaid)
                {
                    sellernotes.SellingPrice = addnotesmodel.SellingPrice;
                }
                else
                {
                    sellernotes.SellingPrice = 0;
                }
                sellernotes.CreatedDate = DateTime.Now;
                sellernotes.CreatedBy   = user.ID;
                sellernotes.IsActive    = true;

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

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

                // if display picture field is not null then save that picture into directory and save directory path into database
                if (addnotesmodel.DisplayPicture != null)
                {
                    string displaypicturefilename = System.IO.Path.GetFileName(addnotesmodel.DisplayPicture.FileName);
                    string displaypicturepath     = "~/Members/" + user.ID + "/" + sellernotes.ID + "/"; //this is vertual path it is convert into physical path using Server.MapPath()

                    CreateDirectoryIfMissing(displaypicturepath);

                    string displaypicturefilepath = Path.Combine(Server.MapPath(displaypicturepath), displaypicturefilename);
                    sellernotes.DisplayPicture = displaypicturepath + displaypicturefilename;
                    addnotesmodel.DisplayPicture.SaveAs(displaypicturefilepath);
                }

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

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

                // attachement files
                foreach (HttpPostedFileBase file in addnotesmodel.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.ID + "/" + sellernotes.ID + "/Attachements/";
                        CreateDirectoryIfMissing(notesattachementpath);
                        string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename);
                        file.SaveAs(notesattachementfilepath);

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

                        // save seller notes attachement
                        context.SellerNotesAttachements.Add(notesattachements);
                        context.SaveChanges();
                    }
                }

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

                return(View(Model));
            }
        }
コード例 #13
0
        public ActionResult AddNotes(Models.AddNotes model, string submitButton)
        {
            var   emailID = User.Identity.Name.ToString();
            Users obj     = dbobj.Users.Where(x => x.EmailID == emailID).FirstOrDefault();

            if (ModelState.IsValid)
            {
                if (model.ID == null)
                {
                    if ((model.File[0] == null) || ((model.IsPaid == true) && (model.PreviewAttachment == null)))
                    {
                        if (model.File[0] == null)
                        {
                            ModelState.AddModelError("File", "File Required");
                        }
                        if (model.PreviewAttachment == null)
                        {
                            ModelState.AddModelError("PreviewAttachment", "PreviewAttachment Required");
                        }
                        ViewBag.Category       = new SelectList(dbobj.NoteCategories, "ID", "Name");
                        ViewBag.Type           = new SelectList(dbobj.NoteTypes, "ID", "Name");
                        ViewBag.Country        = new SelectList(dbobj.Countries, "ID", "Name");
                        ViewBag.ProfilePicture = dbobj.UserProfile.Where(x => x.UserID == obj.RoleID).Select(x => x.ProfilePicture).FirstOrDefault();

                        return(View(model));
                    }
                    string path = Path.Combine(Server.MapPath("~/Members"), obj.ID.ToString());

                    //Checking for directory

                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    SellerNotes noteobj = new SellerNotes();
                    noteobj.SellerID       = obj.ID;
                    noteobj.Title          = model.Title;
                    noteobj.Category       = model.CategoryID;
                    noteobj.NoteType       = model.TypeID;
                    noteobj.NumberofPages  = model.NumberOfPages;
                    noteobj.Description    = model.Description;
                    noteobj.Country        = model.CountryID == null ? 8 : model.CountryID; //if null then country id = 8
                    noteobj.UniversityName = model.InstituteName;
                    noteobj.Course         = model.CourseName == null ? "Other" : model.CourseName;
                    noteobj.CourseCode     = model.CourseCode;
                    noteobj.Professor      = model.Professor;
                    noteobj.IsPaid         = model.IsPaid;
                    noteobj.SellingPrice   = model.Price;
                    if (submitButton == "1")
                    {
                        noteobj.Status = 1;
                    }
                    else
                    {
                        noteobj.Status = 2;
                    }
                    noteobj.ActionedBy  = obj.ID;
                    noteobj.CreatedDate = DateTime.Now;
                    noteobj.IsActive    = true;

                    dbobj.SellerNotes.Add(noteobj);
                    dbobj.SaveChanges();

                    var    NoteID    = noteobj.ID;
                    string finalpath = Path.Combine(Server.MapPath("~/Members/" + obj.ID), NoteID.ToString());

                    if (!Directory.Exists(finalpath))
                    {
                        Directory.CreateDirectory(finalpath);
                    }
                    if (model.DisplayPicture != null && model.DisplayPicture.ContentLength > 0)
                    {
                        var displayimagename = DateTime.Now.ToString().Replace(':', '-').Replace(' ', '_') + Path.GetExtension(model.DisplayPicture.FileName);
                        var ImageSavePath    = Path.Combine(Server.MapPath("~/Members/" + obj.ID + "/" + noteobj.ID + "/") + "DP_" + displayimagename);
                        model.DisplayPicture.SaveAs(ImageSavePath);
                        noteobj.DisplayPicture = Path.Combine(("Members/" + obj.ID + "/" + noteobj.ID + "/"), "DP_" + displayimagename);
                        dbobj.SaveChanges();
                    }
                    else
                    {
                        noteobj.DisplayPicture = "Default/Book.jpg";
                        dbobj.SaveChanges();
                    }

                    if (model.PreviewAttachment != null && model.PreviewAttachment.ContentLength > 0)
                    {
                        var notespreviewname = "Preview_" + DateTime.Now.ToString().Replace(':', '-').Replace(' ', '_') + "_" + Path.GetFileName(model.PreviewAttachment.FileName);
                        var PreviewSavePath  = Path.Combine(Server.MapPath("~/Members/" + obj.ID + "/" + noteobj.ID + "/") + notespreviewname);
                        model.PreviewAttachment.SaveAs(PreviewSavePath);
                        noteobj.NotesPreview = Path.Combine(("Members/" + obj.ID + "/" + noteobj.ID + "/") + notespreviewname);
                        dbobj.SaveChanges();
                    }



                    SellerNotesAttachements natobj = new SellerNotesAttachements();
                    natobj.NoteID      = NoteID; //nat stands for note attachment table
                    natobj.IsActive    = true;
                    natobj.CreatedBy   = obj.ID;
                    natobj.CreatedDate = DateTime.Now;

                    string AttachmentPath = Path.Combine(Server.MapPath("~/Members/" + obj.ID + "/" + noteobj.ID), "Attachment");

                    if (!Directory.Exists(AttachmentPath))
                    {
                        Directory.CreateDirectory(AttachmentPath);
                    }

                    int counter        = 1;
                    var uploadfilepath = "";
                    var uploadfilename = "";

                    foreach (HttpPostedFileBase file in model.File)
                    {
                        //Checking file is available to save.
                        if (file != null)
                        {
                            var InputFileName  = DateTime.Now.ToString().Replace(':', '-').Replace(' ', '_') + "_" + Path.GetFileName(file.FileName);
                            var ServerSavePath = Path.Combine(Server.MapPath("~/Members/" + obj.ID + "/" + noteobj.ID + "/Attachment/") + "Attachment_" + counter + "_" + InputFileName);
                            counter++;
                            //Save file to server folder
                            file.SaveAs(ServerSavePath);
                            uploadfilepath += Path.Combine(("Members/" + obj.ID + "/" + noteobj.ID + "/Attachment/") + "Attachment_" + counter + "_" + InputFileName) + ";";
                            uploadfilename += Path.GetFileName(file.FileName) + ";";
                        }
                    }

                    natobj.FileName = uploadfilename;
                    natobj.FilePath = uploadfilepath;
                    dbobj.SellerNotesAttachements.Add(natobj);
                    dbobj.SaveChanges();
                }
                else //for edit note
                {
                    //saving into database
                    SellerNotes oldnote = dbobj.SellerNotes.Where(x => x.ID == model.ID).FirstOrDefault();
                    oldnote.Title          = model.Title;
                    oldnote.Category       = model.CategoryID;
                    oldnote.NoteType       = model.TypeID;
                    oldnote.NumberofPages  = model.NumberOfPages;
                    oldnote.Description    = model.Description;
                    oldnote.Country        = model.CountryID == null ? 8 : model.CountryID; //if null then country id = 8
                    oldnote.UniversityName = model.InstituteName;
                    oldnote.Course         = model.CourseName == null ? "Other" : model.CourseName;
                    oldnote.CourseCode     = model.CourseCode;
                    oldnote.Professor      = model.Professor;
                    oldnote.IsPaid         = model.IsPaid;
                    oldnote.SellingPrice   = model.Price;

                    if (submitButton == "1")
                    {
                        oldnote.Status = 1;
                    }
                    else
                    {
                        oldnote.Status = 2;
                    }
                    oldnote.ActionedBy   = obj.ID;
                    oldnote.ModifiedDate = DateTime.Now;
                    oldnote.IsActive     = true;

                    dbobj.Entry(oldnote).State = System.Data.Entity.EntityState.Modified;
                    dbobj.SaveChanges();

                    var    NoteID    = oldnote.ID;
                    string finalpath = Path.Combine(Server.MapPath("~/Members/" + obj.ID), NoteID.ToString());

                    //  For New Display Picture
                    if (model.DisplayPicture != null && model.DisplayPicture.ContentLength > 0)
                    {
                        var      OldDisplayPicture = Server.MapPath(oldnote.DisplayPicture);
                        FileInfo file = new FileInfo(OldDisplayPicture);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                        var displayimagename = DateTime.Now.ToString().Replace(':', '-').Replace(' ', '_') + Path.GetExtension(model.DisplayPicture.FileName);
                        var ImageSavePath    = Path.Combine(Server.MapPath("~/Members/" + obj.ID + "/" + oldnote.ID + "/") + "DP_" + displayimagename);
                        model.DisplayPicture.SaveAs(ImageSavePath);
                        oldnote.DisplayPicture = Path.Combine(("Members/" + obj.ID + "/" + oldnote.ID + "/"), "DP_" + displayimagename);
                        dbobj.SaveChanges();
                    }

                    //  For New PreviewAttachment
                    if (model.PreviewAttachment != null && model.PreviewAttachment.ContentLength > 0)
                    {
                        var      OldPreviewAttachment = Server.MapPath(oldnote.NotesPreview);
                        FileInfo file = new FileInfo(OldPreviewAttachment);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                        var notespreviewname = "Preview_" + DateTime.Now.ToString().Replace(':', '-').Replace(' ', '_') + "_" + Path.GetFileName(model.PreviewAttachment.FileName);
                        var PreviewSavePath  = Path.Combine(Server.MapPath("~/Members/" + obj.ID + "/" + oldnote.ID + "/") + notespreviewname);
                        model.PreviewAttachment.SaveAs(PreviewSavePath);
                        oldnote.NotesPreview = Path.Combine(("Members/" + obj.ID + "/" + oldnote.ID + "/") + notespreviewname);
                        dbobj.SaveChanges();
                    }

                    if (model.File[0] != null)      // New file Uploaded
                    {
                        SellerNotesAttachements oldnatobj = dbobj.SellerNotesAttachements.Where(x => x.NoteID == NoteID).FirstOrDefault();
                        oldnatobj.ModifiedDate = DateTime.Now;

                        string AttachmentPath = Path.Combine(Server.MapPath("~/Members/" + obj.ID + "/" + oldnote.ID), "Attachment");

                        Directory.Delete(AttachmentPath, true);
                        Directory.CreateDirectory(AttachmentPath);

                        int counter        = 1;
                        var uploadfilepath = "";
                        var uploadfilename = "";

                        foreach (HttpPostedFileBase file in model.File)
                        {
                            //Checking file is available to save.
                            if (file != null)
                            {
                                var InputFileName  = DateTime.Now.ToString().Replace(':', '-').Replace(' ', '_') + "_" + Path.GetFileName(file.FileName);
                                var ServerSavePath = Path.Combine(Server.MapPath("Members/" + obj.ID + "/" + oldnote.ID + "/Attachment/") + "Attachment_" + counter + "_" + InputFileName);
                                counter++;
                                //Save file to server folder
                                file.SaveAs(ServerSavePath);
                                uploadfilepath += Path.Combine(("Members/" + obj.ID + "/" + oldnote.ID + "/Attachment/") + "Attachment_" + counter + "_" + InputFileName) + ";";
                                uploadfilename += Path.GetFileName(file.FileName) + ";";
                            }
                        }

                        oldnatobj.FileName           = uploadfilename;
                        oldnatobj.FilePath           = uploadfilepath;
                        dbobj.Entry(oldnatobj).State = System.Data.Entity.EntityState.Modified;
                        dbobj.SaveChanges();
                    }
                }
                return(RedirectToAction("Dashboard", "Dashboard"));
            }
            ViewBag.Category       = new SelectList(dbobj.NoteCategories, "ID", "Name");
            ViewBag.Type           = new SelectList(dbobj.NoteTypes, "ID", "Name");
            ViewBag.Country        = new SelectList(dbobj.Countries, "ID", "Name");
            ViewBag.ProfilePicture = dbobj.UserProfile.Where(x => x.UserID == obj.ID).Select(x => x.ProfilePicture).FirstOrDefault();
            return(View());
        }