コード例 #1
0
        public ActionResult UpdateAdminStatus(int uid, int status)
        {
            var   emailid    = User.Identity.Name.ToString();
            Users superadmin = dbobj.Users.Where(x => x.EmailID == emailid).FirstOrDefault();

            Users obj   = dbobj.Users.Where(x => x.ID == uid).FirstOrDefault();
            Admin adobj = dbobj.Admin.Where(x => x.UserID == uid).FirstOrDefault();

            if (status == 0)    // Deactivate Admin
            {
                obj.IsActive     = false;
                obj.ModifiedDate = DateTime.Now;
                obj.ModifiedBy   = superadmin.ID;

                adobj.IsActive     = false;
                adobj.ModifiedDate = DateTime.Now;
                adobj.ModifiedBy   = superadmin.ID;
            }
            else    // Activate Admin
            {
                obj.IsActive     = true;
                obj.ModifiedDate = DateTime.Now;
                obj.ModifiedBy   = superadmin.ID;

                adobj.IsActive     = true;
                adobj.ModifiedDate = DateTime.Now;
                adobj.ModifiedBy   = superadmin.ID;
            }

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

            return(RedirectToAction("ManageAdmin"));
        }
コード例 #2
0
        public ActionResult ChangePassword(Models.ChangePassword model)
        {
            var   emailID = User.Identity.Name.ToString();
            Users obj     = dbobj.Users.Where(x => x.EmailID == emailID).FirstOrDefault();

            if (ModelState.IsValid)
            {
                if (String.Compare(model.OldPassword, obj.Password) == 0)
                {
                    obj.Password     = model.NewPassword;
                    obj.ModifiedDate = DateTime.Now;

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

                    FormsAuthentication.SignOut();
                    return(RedirectToAction("Login"));
                }
                else
                {
                    ModelState.AddModelError("OldPassword", "OldPassword Is Incorrect");
                }
            }
            return(View());
        }
コード例 #3
0
 public ActionResult UpdatePassword(User user)
 {
     if (Session["userId"] == null)
     {
         return(RedirectToAction("Login", "Auth"));
     }
     else
     {
         int  userId      = (int)Session["userID"];
         User currentUser = data.Users.Find(user.UserID);
         if (user.Password.Equals(currentUser.Password))
         {
             currentUser.Password           = user.NewPassword;
             currentUser.ConfirmPassword    = user.NewPassword;
             currentUser.NewPassword        = user.NewPassword;
             currentUser.ConfirmNewPassword = user.NewPassword;
             data.Entry(currentUser).State  = System.Data.Entity.EntityState.Modified;
             data.SaveChanges();
             return(RedirectToAction("Login", "Auth"));
         }
         else
         {
             return(Content("The Old Password Not Matched !!!"));
             //return RedirectToAction("ChangePassword", "Auth");
         }
     }
 }
コード例 #4
0
        public ActionResult AdminProfile(NotesMarketplace.Models.AdminProfile model)
        {
            var   emailid = User.Identity.Name.ToString();
            Users obj     = dbobj.Users.Where(x => x.EmailID == emailid).FirstOrDefault();

            var apobj = dbobj.Admin.Where(x => x.UserID == obj.ID).FirstOrDefault();

            obj.FirstName        = model.FirstName;
            obj.LastName         = model.LastName;
            obj.EmailID          = model.Email;
            apobj.SecondaryEmail = model.SecondaryEmail;
            apobj.CountryCode    = model.CountryCode;
            apobj.PhoneNumber    = model.PhoneNumber;

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

            //Checking for directory

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

            //Saving Profile Picture
            if (model.ProfilePicture != null && model.ProfilePicture.ContentLength > 0)
            {
                var ProfilePicture = DateTime.Now.ToString().Replace(':', '-').Replace(' ', '_') + Path.GetExtension(model.ProfilePicture.FileName);
                var ImageSavePath  = Path.Combine(Server.MapPath("~/Members/" + obj.ID + "/") + "DP_" + ProfilePicture);
                model.ProfilePicture.SaveAs(ImageSavePath);
                apobj.ProfilePicture = Path.Combine(("Members/" + obj.ID + "/"), "DP_" + ProfilePicture);
            }
            else
            {
                apobj.ProfilePicture = dbobj.SystemConfigurations.Where(x => x.Key == "DefaultProfilePicture").Select(x => x.Value).ToString();
            }

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

            return(RedirectToAction("AdminDashboard", "Admin"));
        }
コード例 #5
0
        public ActionResult Deactivate(int uid)
        {
            var   emailid = User.Identity.Name.ToString();
            Users obj     = dbobj.Users.Where(x => x.EmailID == emailid).FirstOrDefault();

            Users       userobj = dbobj.Users.Where(x => x.ID == uid).FirstOrDefault();
            UserProfile upobj   = dbobj.UserProfile.Where(x => x.UserID == uid).FirstOrDefault();

            userobj.IsActive = false;
            upobj.IsActive   = false;

            var usernotes = dbobj.SellerNotes.Where(x => x.SellerID == uid);

            foreach (var item in usernotes)
            {
                item.IsActive           = false;
                dbobj.Entry(item).State = System.Data.Entity.EntityState.Modified;
            }

            /*var user_notes_attachments = dbobj.NoteTable.Where(x => x.UID == uid);
             *
             * foreach (var item in user_notes_attachments)
             * {
             *  item.IsActive = false;
             * }*/

            dbobj.Entry(userobj).State = System.Data.Entity.EntityState.Modified;
            dbobj.Entry(upobj).State   = System.Data.Entity.EntityState.Modified;

            dbobj.SaveChanges();

            return(RedirectToAction("AllMembers"));
        }
コード例 #6
0
        public ActionResult EditCountry(AddCountry model)
        {
            var   emailid = User.Identity.Name.ToString();
            Users admin   = dbobj.Users.Where(x => x.EmailID == emailid).FirstOrDefault();

            if (ModelState.IsValid)
            {
                Countries obj = dbobj.Countries.Where(x => x.ID == model.CountryID).FirstOrDefault();

                obj.Name         = model.CountryName;
                obj.CountryCode  = model.CountryCode;
                obj.ModifiedDate = DateTime.Now;
                obj.ModifiedBy   = admin.ID;

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

                return(RedirectToAction("ManageCountries"));
            }
            ViewBag.ProfilePicture = dbobj.Admin.Where(x => x.UserID == admin.ID).Select(x => x.ProfilePicture).FirstOrDefault();
            return(View());
        }
コード例 #7
0
        public ActionResult AllowDownload(int tid)
        {
            var   emailid = User.Identity.Name.ToString();
            Users obj     = dbobj.Users.Where(x => x.EmailID == emailid).FirstOrDefault();

            Transection deal = dbobj.Transection.Where(x => x.ID == tid).FirstOrDefault();

            deal.IsAllowed = true;

            dbobj.Entry(deal).State = System.Data.Entity.EntityState.Modified;
            dbobj.SaveChanges();
            NotifyBuyer(deal.Users.EmailID, deal.Users.FirstName, obj.FirstName);

            return(RedirectToAction("BuyerRequest"));
        }
コード例 #8
0
        public ActionResult DeleteSpamReports(int sid)
        {
            SpamTable report = dbobj.SpamTable.Where(x => x.ID == sid).FirstOrDefault();
            int       nid    = report.NoteID;

            dbobj.SpamTable.Remove(report);
            dbobj.SaveChanges();

            var book = dbobj.SellerNotes.Where(x => x.ID == nid).FirstOrDefault();

            int total_spams = dbobj.SpamTable.Where(x => x.NoteID == nid).Count();

            book.TotalSpams = total_spams;

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

            return(RedirectToAction("SpamReports"));
        }
コード例 #9
0
        public ActionResult AddReview(int nid, int rate, string Comments)
        {
            var   emailid = User.Identity.Name.ToString();
            Users obj     = dbobj.Users.Where(x => x.EmailID == emailid).FirstOrDefault();

            var oldreview = dbobj.SellerNotesReviews.Where(x => x.NoteID == nid && x.ReviewedByID == obj.ID).FirstOrDefault();

            if (oldreview == null)   //New Review
            {
                SellerNotesReviews review = new SellerNotesReviews();

                review.NoteID       = nid;
                review.ReviewedByID = obj.ID;
                review.Ratings      = rate;
                review.Comments     = Comments;
                review.CreatedDate  = DateTime.Now;

                dbobj.SellerNotesReviews.Add(review);
                dbobj.SaveChanges();

                // Adding Ratings in note table

                var book = dbobj.SellerNotes.Where(x => x.ID == nid).FirstOrDefault();

                int     total_reviews = dbobj.SellerNotesReviews.Where(x => x.NoteID == nid).Count();
                decimal total_stars   = dbobj.SellerNotesReviews.Where(x => x.NoteID == nid).Select(x => x.Ratings).Sum();

                book.TotalReviews = total_reviews;
                book.Rating       = ((double)total_stars / total_reviews) * 20;

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

                // ------------------------------------------------------------

                return(RedirectToAction("MyDownloads"));
            }
            else   //Update Review
            {
                oldreview.Ratings  = rate;
                oldreview.Comments = Comments;

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

                // Adding Ratings in note table

                var book = dbobj.SellerNotes.Where(x => x.ID == nid).FirstOrDefault();

                int     total_reviews = dbobj.SellerNotesReviews.Where(x => x.NoteID == nid).Count();
                decimal total_stars   = dbobj.SellerNotesReviews.Where(x => x.NoteID == nid).Select(x => x.Ratings).Sum();

                book.TotalReviews = total_reviews;
                book.Rating       = ((double)total_stars / total_reviews) * 20;

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

                // ------------------------------------------------------------

                return(RedirectToAction("MyDownloads"));
            }
        }
コード例 #10
0
        public ActionResult UserProfile(Models.UserProfile model)
        {
            var   emailid = User.Identity.Name.ToString();
            Users obj     = dbobj.Users.Where(x => x.EmailID == emailid).FirstOrDefault();

            if (ModelState.IsValid)
            {
                var isnew = dbobj.UserProfile.Where(x => x.UserID == obj.ID).FirstOrDefault();

                if (isnew == null)   // For new user
                {
                    UserProfile upobj = new UserProfile();
                    upobj.UserID = obj.ID;
                    upobj.DOB    = model.DateOfBirth;
                    upobj.Gender = model.Gender;
                    upobj.PhoneNumberCountryCode = model.CountryCode;
                    upobj.PhoneNumber            = model.PhoneNumber;
                    upobj.AddressLine1           = model.AddressLine1;
                    upobj.AddressLine2           = model.AddressLine2;
                    upobj.City        = model.City;
                    upobj.State       = model.State;
                    upobj.ZipCode     = model.ZipCode;
                    upobj.Country     = model.CountryID;
                    upobj.University  = model.University;
                    upobj.College     = model.College;
                    upobj.CreatedDate = DateTime.Now;
                    upobj.CreatedBy   = obj.ID;
                    upobj.IsActive    = true;

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

                    //Checking for directory

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

                    //Saving Profile Picture
                    if (model.ProfilePicture != null && model.ProfilePicture.ContentLength > 0)
                    {
                        var ProfilePicture = DateTime.Now.ToString().Replace(':', '-').Replace(' ', '_') + Path.GetExtension(model.ProfilePicture.FileName);
                        var ImageSavePath  = Path.Combine(Server.MapPath("~/Members/" + obj.ID + "/") + "DP_" + ProfilePicture);
                        model.ProfilePicture.SaveAs(ImageSavePath);
                        upobj.ProfilePicture = Path.Combine(("Members/" + obj.ID + "/"), "DP_" + ProfilePicture);
                        dbobj.SaveChanges();
                    }
                    else
                    {
                        /*upobj.ProfilePicture = "Default/User.jpg";*/
                        upobj.ProfilePicture = dbobj.SystemConfigurations.Where(x => x.Key == "DefaultProfilePicture").Select(x => x.Value).ToString();
                        dbobj.SaveChanges();
                    }

                    dbobj.UserProfile.Add(upobj);
                    dbobj.SaveChanges();

                    return(RedirectToAction("SearchNotes", "SearchNotes"));
                }
                else
                {
                    UserProfile oldupobj = dbobj.UserProfile.Where(x => x.UserID == obj.ID).FirstOrDefault();

                    Users olduserobj = dbobj.Users.Where(x => x.ID == obj.ID).FirstOrDefault();

                    olduserobj.FirstName    = model.FirstName;
                    olduserobj.LastName     = model.LastName;
                    olduserobj.EmailID      = model.EmailID;
                    olduserobj.ModifiedDate = DateTime.Now;
                    olduserobj.ModifiedBy   = olduserobj.ID;

                    oldupobj.DOB    = model.DateOfBirth;
                    oldupobj.Gender = model.Gender;
                    oldupobj.PhoneNumberCountryCode = model.CountryCode;
                    oldupobj.PhoneNumber            = model.PhoneNumber;
                    oldupobj.AddressLine1           = model.AddressLine1;
                    oldupobj.AddressLine2           = model.AddressLine2;
                    oldupobj.City         = model.City;
                    oldupobj.State        = model.State;
                    oldupobj.ZipCode      = model.ZipCode;
                    oldupobj.Country      = model.CountryID;
                    oldupobj.University   = model.University;
                    oldupobj.College      = model.College;
                    oldupobj.ModifiedDate = DateTime.Now;
                    oldupobj.ModifiedBy   = obj.ID;

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

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

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

                    return(RedirectToAction("SearchNotes", "SearchNotes"));
                }
            }
            ViewBag.ProfilePicture = dbobj.UserProfile.Where(x => x.UserID == obj.ID).Select(x => x.ProfilePicture).FirstOrDefault();
            return(View(model));
        }
コード例 #11
0
        public ActionResult Download(int nid)
        {
            var   emailid = User.Identity.Name.ToString();
            Users obj     = dbobj.Users.Where(x => x.EmailID == emailid).FirstOrDefault();

            SellerNotes noteobj = dbobj.SellerNotes.Where(x => x.ID == nid).FirstOrDefault();

            Users sellerobj = dbobj.Users.Where(x => x.ID == noteobj.SellerID).FirstOrDefault();

            Transection deal = dbobj.Transection.Where(x => x.NoteID == nid && x.BuyerID == obj.ID).FirstOrDefault();

            if (obj.ID == noteobj.SellerID)     // Users own book
            {
                using (ZipFile zip = new ZipFile())
                {
                    zip.AddDirectory(Server.MapPath("~/Members/" + noteobj.SellerID + "/" + nid + "/" + "Attachment"));

                    MemoryStream output = new MemoryStream();
                    zip.Save(output);
                    return(File(output.ToArray(), "Attachment/zip", noteobj.Title + ".zip"));
                }
            }
            else
            {
                if (deal == null)                // New Transection
                {
                    if (noteobj.IsPaid == false) // Download Free Notes
                    {
                        Transection tobj = new Transection();
                        tobj.NoteID       = nid;
                        tobj.Title        = noteobj.Title;
                        tobj.Category     = noteobj.NoteCategories.Name;
                        tobj.IsPaid       = false;
                        tobj.Price        = noteobj.SellingPrice;
                        tobj.BuyerID      = obj.ID;
                        tobj.SellerID     = noteobj.SellerID;
                        tobj.IsAllowed    = true;
                        tobj.IsDownloaded = true;
                        tobj.DownloadDate = DateTime.Now;
                        tobj.Status       = noteobj.ReferenceData.Value;
                        tobj.CreatedDate  = DateTime.Now;

                        dbobj.Transection.Add(tobj);
                        dbobj.SaveChanges();

                        using (ZipFile zip = new ZipFile())
                        {
                            zip.AddDirectory(Server.MapPath("~/Members/" + noteobj.SellerID + "/" + nid + "/" + "Attachment"));

                            MemoryStream output = new MemoryStream();
                            zip.Save(output);
                            return(File(output.ToArray(), "Attachment/zip", noteobj.Title + ".zip"));
                        }
                    }
                    else    // Download Paid Notes
                    {
                        Transection tobj = new Transection();
                        tobj.NoteID       = nid;
                        tobj.Title        = noteobj.Title;
                        tobj.Category     = noteobj.NoteCategories.Name;
                        tobj.IsPaid       = true;
                        tobj.Price        = noteobj.SellingPrice;
                        tobj.BuyerID      = obj.ID;
                        tobj.SellerID     = noteobj.SellerID;
                        tobj.IsAllowed    = false;
                        tobj.IsDownloaded = false;
                        tobj.DownloadDate = null;
                        tobj.Status       = noteobj.ReferenceData.Value;
                        tobj.CreatedDate  = DateTime.Now;

                        dbobj.Transection.Add(tobj);
                        dbobj.SaveChanges();
                        NotifySeller(sellerobj.EmailID, obj.FirstName, sellerobj.FirstName);
                        //return RedirectToAction("NoteDetails", new { nid });
                        ViewBag.CurrentUserName = obj.FirstName;
                        return(RedirectToAction("NoteDetails", new { nid }));
                        //return PartialView("ThanksPopup", noteobj);
                    }
                }
                else                             // Old Transection Available
                {
                    if (noteobj.IsPaid == false) // Download Free Notes
                    {
                        using (ZipFile zip = new ZipFile())
                        {
                            zip.AddDirectory(Server.MapPath("~/Members/" + noteobj.SellerID + "/" + nid + "/" + "Attachment"));

                            MemoryStream output = new MemoryStream();
                            zip.Save(output);
                            return(File(output.ToArray(), "Attachment/zip", noteobj.Title + ".zip"));
                        }
                    }
                    else    // Download Paid Notes
                    {
                        if ((bool)deal.IsAllowed)
                        {
                            deal.IsDownloaded = true;
                            deal.DownloadDate = DateTime.Now;

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

                            using (ZipFile zip = new ZipFile())
                            {
                                zip.AddDirectory(Server.MapPath("~/Members/" + noteobj.SellerID + "/" + nid + "/" + "Attachment"));

                                MemoryStream output = new MemoryStream();
                                zip.Save(output);
                                return(File(output.ToArray(), "Attachment/zip", noteobj.Title + ".zip"));
                            }
                        }
                        else
                        {
                            return(RedirectToAction("NoteDetails", nid));
                        }
                    }
                }
            }
        }
コード例 #12
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());
        }