示例#1
0
        public ActionResult EditCategory(AddCategory obj)
        {
            if (ModelState.IsValid)
            {
                var user     = dobj.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();
                var category = dobj.NoteCategories.Where(x => x.ID == obj.ID).FirstOrDefault();

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

                category.Name         = obj.Name.Trim();
                category.Description  = obj.Description.Trim();
                category.ModifiedDate = DateTime.Now;
                category.ModifiedBy   = user.ID;

                dobj.Entry(category).State = EntityState.Modified;
                dobj.SaveChanges();

                return(RedirectToAction("ManageCategory"));
            }
            else
            {
                return(View(obj));
            }
        }
示例#2
0
        public ActionResult MakeNoteInReview(int id)
        {
            // get note by id
            var note = dobj.NoteDetail.Where(x => x.ID == id).FirstOrDefault();

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

            // get logged in user
            var user = dobj.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            // notes status id for in review
            var inreviewid = dobj.ReferenceData.Where(x => x.Value.ToLower() == "in review").Select(x => x.ID).FirstOrDefault();

            // update status
            note.Status       = inreviewid;
            note.ModifiedDate = DateTime.Now;
            note.ModifiedBy   = user.ID;

            // save note in database
            dobj.Entry(note).State = EntityState.Modified;
            dobj.SaveChanges();

            return(RedirectToAction("NotesUnderReview"));
        }
        public ActionResult UnPublishNote(FormCollection form)
        {
            int    noteid = Convert.ToInt32(form["noteid"]);
            string remark = form["unpublish-remark"];

            var user = dobj.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();
            var note = dobj.NoteDetail.Where(x => x.ID == noteid).FirstOrDefault();

            // get note status removed id
            int removedid = dobj.ReferenceData.Where(x => x.Value.ToLower() == "removed").Select(x => x.ID).FirstOrDefault();

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

            // update note status
            note.Status       = removedid;
            note.AdminRemarks = remark;
            note.ModifiedBy   = user.ID;
            note.ModifiedDate = DateTime.Now;
            note.ActionedBy   = user.ID;
            // save note in database
            dobj.Entry(note).State = EntityState.Modified;
            dobj.SaveChanges();

            // get seller user objecct
            var seller = dobj.Users.Where(x => x.ID == note.SellerID).FirstOrDefault();

            // send mail to seller
            UnpublishNoteTemplate(remark, seller, note);

            return(RedirectToAction("Dashboard", "Admin"));
        }
示例#4
0
        public ActionResult ChangePassword(Models.ChangePassword model)
        {
            var emailid = User.Identity.Name.ToString();

            Context.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());
        }
        public ActionResult DeactiveMember(int memberid)
        {
            // get logged in admin
            var user = dobj.Users.Where(x => x.EmailID == User.Identity.Name).First();

            // get ids of note status removed and published
            var removedid   = dobj.ReferenceData.Where(x => x.Value.ToLower() == "removed").Select(x => x.ID).FirstOrDefault();
            var publishedid = dobj.ReferenceData.Where(x => x.Value.ToLower() == "published").Select(x => x.ID).FirstOrDefault();

            // get member by member id
            var member = dobj.Users.Where(x => x.ID == memberid && x.IsActive == true).First();

            // make member inactive
            member.IsActive     = false;
            member.ModifiedDate = DateTime.Now;
            member.ModifiedBy   = user.ID;

            // save updated member record
            dobj.Entry(member).State = EntityState.Modified;
            dobj.SaveChanges();

            // get member's published notes list
            var notelist = dobj.NoteDetail.Where(x => x.SellerID == member.ID && x.Status == publishedid && x.IsActive == true).ToList();

            // make member's each published note status removed
            foreach (var note in notelist)
            {
                note.Status       = removedid;
                note.ModifiedDate = DateTime.Now;
                note.ModifiedBy   = user.ID;

                dobj.Entry(note).State = EntityState.Modified;
                dobj.SaveChanges();
            }

            return(RedirectToAction("Members", "AdminMembers"));
        }
        public ActionResult DownloadNotes(int noteid)
        {
            //find note
            var note = dobj.NoteDetail.Find(noteid);

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

            var noteattachement = dobj.NotesAttachments.Where(x => x.NoteID == note.ID).FirstOrDefault();

            var user = dobj.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            // variable for attachement path
            string path;

            if (note.SellerID == user.ID)
            {
                // get attachement path
                path = Server.MapPath(noteattachement.FilePath);

                DirectoryInfo dir = new DirectoryInfo(path);

                // create zip of attachement
                using (var memoryStream = new MemoryStream())
                {
                    using (var ziparchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                    {
                        foreach (var item in dir.GetFiles())
                        {
                            // file path is attachement path + file name
                            string filepath = path + item.ToString();
                            ziparchive.CreateEntryFromFile(filepath, item.ToString());
                        }
                    }
                    // return zip
                    return(File(memoryStream.ToArray(), "application/zip", note.Title + ".zip"));
                }
            }

            // if note is free then we need to add entry in download table with allow download is true

            if (note.IsPaid == false)
            {
                // if user has already downloaded note then get download object
                var downloadfreenote = dobj.Downloads.Where(x => x.NoteID == noteid && x.Downloader == user.ID && x.IsSellerHasAllowedDownload == true && x.AttachmentPath != null).FirstOrDefault();

                // user is not downloaded note
                if (downloadfreenote == null)
                {
                    Downloads download = new Downloads
                    {
                        NoteID     = note.ID,
                        Seller     = note.SellerID,
                        Downloader = user.ID,
                        IsSellerHasAllowedDownload = true,
                        AttachmentPath             = noteattachement.FilePath,
                        IsAttachmentDownloaded     = true,
                        AttachmentDownloadedDate   = DateTime.Now,
                        IsPaid         = note.IsPaid,
                        PurchasedPrice = note.SellingPrice,
                        NoteTitle      = note.Title,
                        NoteCategory   = note.NoteCategories.Name,
                        CreatedDate    = DateTime.Now,
                        CreatedBy      = user.ID,
                    };


                    dobj.Downloads.Add(download);
                    dobj.SaveChanges();

                    path = Server.MapPath(download.AttachmentPath);
                }

                // if user is already downloaded note then get attachement path
                else
                {
                    path = Server.MapPath(downloadfreenote.AttachmentPath);
                }

                DirectoryInfo dir = new DirectoryInfo(path);


                //zip of attachment

                using (var memoryStream = new MemoryStream())
                {
                    using (var ziparchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                    {
                        foreach (var item in dir.GetFiles())
                        {
                            // file path is attachement path + file name
                            string filepath = path + item.ToString();
                            ziparchive.CreateEntryFromFile(filepath, item.ToString());
                        }
                    }
                    // return zip
                    return(File(memoryStream.ToArray(), "application/zip", note.Title + ".zip"));
                }
            }


            //paid note
            else
            {
                // get download object
                var downloadpaidnote = dobj.Downloads.Where(x => x.NoteID == noteid && x.Downloader == user.ID && x.IsSellerHasAllowedDownload == true && x.AttachmentPath != null).FirstOrDefault();

                // if user is not already downloaded
                if (downloadpaidnote != null)
                {
                    // if user is download note first time then we need to update following record in download table
                    if (downloadpaidnote.IsAttachmentDownloaded == false)
                    {
                        downloadpaidnote.IsAttachmentDownloaded   = true;
                        downloadpaidnote.AttachmentDownloadedDate = DateTime.Now;
                        downloadpaidnote.ModifiedDate             = DateTime.Now;
                        downloadpaidnote.ModifiedBy = user.ID;

                        // update ans save data in database
                        dobj.Entry(downloadpaidnote).State = EntityState.Modified;
                        dobj.SaveChanges();
                    }

                    path = Server.MapPath(downloadpaidnote.AttachmentPath);

                    DirectoryInfo dir = new DirectoryInfo(path);

                    //  zip of attachement
                    using (var memoryStream = new MemoryStream())
                    {
                        using (var ziparchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                        {
                            foreach (var item in dir.GetFiles())
                            {
                                // file path is attachement path + file name
                                string filepath = path + item.ToString();
                                ziparchive.CreateEntryFromFile(filepath, item.ToString());
                            }
                        }

                        return(File(memoryStream.ToArray(), "application/zip", note.Title + ".zip"));
                    }
                }
                return(RedirectToAction("NoteDetail", "SearchNotes", new { id = noteid }));
            }
        }
        public ActionResult MyProfile(AdminProfile obj)
        {
            // get logged in user
            var user = dobj.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            if (ModelState.IsValid)
            {
                // get  logged in user profile
                var userprofile = dobj.AdminDetail.Where(x => x.AdminID == user.ID).FirstOrDefault();

                if (userprofile != null)
                {
                    // check if secondary email is already exists in User or Admin table or not
                    // if email already exists then give error
                    bool secondaryemailalreadyexistsinusers = dobj.Users.Where(x => x.EmailID == obj.SecondaryEmail).Any();
                    bool secondaryemailalreadyexistsinadmin = dobj.AdminDetail.Where(x => x.SecondaryEmail == obj.Email && x.AdminID != user.ID).Any();
                    if (secondaryemailalreadyexistsinusers || secondaryemailalreadyexistsinadmin)
                    {
                        ModelState.AddModelError("SecondaryEmail", "This email address is already exists");
                        obj.CountryCodeList = dobj.Countries.Where(x => x.IsActive).OrderBy(x => x.CountryCode).Select(x => x.CountryCode).ToList();
                        return(View(obj));
                    }

                    // update user's data
                    user.FirstName = obj.FirstName.Trim();
                    user.LastName  = obj.LastName.Trim();
                    // update userprofile's data
                    if (obj.SecondaryEmail != null)
                    {
                        userprofile.SecondaryEmail = obj.SecondaryEmail.Trim();
                    }
                    userprofile.CountryCode = obj.CountryCode.Trim();
                    userprofile.PhoneNumber = obj.PhoneNumber.Trim();

                    // user upploaded profile picture and there is also previous profile picture then delete previous profile picture
                    if (userprofile.ProfilePicture != null && obj.ProfilePicture != null)
                    {
                        string   path = Server.MapPath(userprofile.ProfilePicture);
                        FileInfo file = new FileInfo(path);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                    }

                    // save new profile picture and update data in userprofile table
                    if (obj.ProfilePicture != null)
                    {
                        // get extension
                        string fileextension = System.IO.Path.GetExtension(obj.ProfilePicture.FileName);
                        // set new name of file
                        string newfilename = "DP_" + DateTime.Now.ToString("ddMMyyyy_hhmmss") + fileextension;
                        // set where to save picture
                        string profilepicturepath = "~/Members/" + userprofile.AdminID + "/";
                        // create directory if not exists
                        CreateDirectoryIfMissing(profilepicturepath);
                        // get physical path and save profile picture there
                        string path = Path.Combine(Server.MapPath(profilepicturepath), newfilename);
                        obj.ProfilePicture.SaveAs(path);
                        // save path in database
                        userprofile.ProfilePicture = profilepicturepath + newfilename;
                    }


                    userprofile.ModifiedDate = DateTime.Now;
                    userprofile.ModifiedBy   = user.ID;

                    dobj.Entry(user).State        = EntityState.Modified;
                    dobj.Entry(userprofile).State = EntityState.Modified;
                    dobj.SaveChanges();
                }
                else
                {
                    AdminDetail admin = new AdminDetail();
                    admin.AdminID = user.ID;
                    bool secondaryemailalreadyexistsinusers       = dobj.Users.Where(x => x.EmailID == obj.SecondaryEmail).Any();
                    bool secondaryemailalreadyexistsinuserprofile = dobj.AdminDetail.Where(x => x.SecondaryEmail == obj.Email && x.AdminID != user.ID).Any();
                    if (secondaryemailalreadyexistsinusers || secondaryemailalreadyexistsinuserprofile)
                    {
                        ModelState.AddModelError("SecondaryEmail", "This email address is already exists");
                        obj.CountryCodeList = dobj.Countries.Where(x => x.IsActive).OrderBy(x => x.CountryCode).Select(x => x.CountryCode).ToList();
                        return(View(obj));
                    }

                    // update user's data
                    user.FirstName = obj.FirstName.Trim();
                    user.LastName  = obj.LastName.Trim();
                    // update userprofile's data
                    if (obj.SecondaryEmail != null)
                    {
                        admin.SecondaryEmail = obj.SecondaryEmail.Trim();
                    }
                    admin.CountryCode = obj.CountryCode.Trim();
                    admin.PhoneNumber = obj.PhoneNumber.Trim();

                    // user upploaded profile picture and there is also previous profile picture then delete previous profile picture
                    if (admin.ProfilePicture != null && obj.ProfilePicture != null)
                    {
                        string   path = Server.MapPath(admin.ProfilePicture);
                        FileInfo file = new FileInfo(path);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                    }

                    // save new profile picture and update data in userprofile table
                    if (obj.ProfilePicture != null)
                    {
                        // get extension
                        string fileextension = System.IO.Path.GetExtension(obj.ProfilePicture.FileName);
                        // set new name of file
                        string newfilename = "DP_" + DateTime.Now.ToString("ddMMyyyy_hhmmss") + fileextension;
                        // set where to save picture
                        string profilepicturepath = "~/Members/" + userprofile.AdminID + "/";
                        // create directory if not exists
                        CreateDirectoryIfMissing(profilepicturepath);
                        // get physical path and save profile picture there
                        string path = Path.Combine(Server.MapPath(profilepicturepath), newfilename);
                        obj.ProfilePicture.SaveAs(path);
                        // save path in database
                        admin.ProfilePicture = profilepicturepath + newfilename;
                    }

                    dobj.AdminDetail.Add(admin);
                    dobj.SaveChanges();

                    dobj.Entry(user).State = EntityState.Modified;
                    dobj.SaveChanges();
                }
                return(RedirectToAction("Dashboard", "Admin"));
            }

            else
            {
                obj.CountryCodeList = dobj.Countries.Where(x => x.IsActive).OrderBy(x => x.CountryCode).Select(x => x.CountryCode).ToList();
                return(View(obj));
            }
        }
        public ActionResult UserProfile(UserProfile userprofilemodel)
        {
            var user = dbobj.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            if (ModelState.IsValid)
            {
                if (userprofilemodel.ProfilePicture != null)
                {
                    //image size limit 10MB
                    var profilepicsize = userprofilemodel.ProfilePicture.ContentLength;
                    if (profilepicsize > 10 * 1024 * 1024)
                    {
                        // error if image size is more than 10MB
                        ModelState.AddModelError("ProfilePicture", "Image size limit is 10 MB");
                        userprofilemodel.CountryList = dbobj.Countries.Where(x => x.IsActive == true).ToList();
                        userprofilemodel.GenderList  = dbobj.ReferenceData.Where(x => x.RefCategory == "Gender" && x.IsActive == true).ToList();
                        return(View(userprofilemodel));
                    }
                }


                var profile = dbobj.UserProfileDetail.Where(x => x.UserID == user.ID).FirstOrDefault();

                //edit profile
                if (profile != null)
                {
                    profile.DOB          = userprofilemodel.DOB;
                    profile.Gender       = userprofilemodel.Gender;
                    profile.CountryCode  = userprofilemodel.CountryCode.Trim();
                    profile.PhoneNumber  = userprofilemodel.PhoneNumber.Trim();
                    profile.AddressLine1 = userprofilemodel.AddressLine1.Trim();
                    profile.AddressLine2 = userprofilemodel.AddressLine2.Trim();
                    profile.City         = userprofilemodel.City.Trim();
                    profile.State        = userprofilemodel.State.Trim();
                    profile.ZipCode      = userprofilemodel.ZipCode.Trim();
                    profile.Country      = userprofilemodel.Country.Trim();
                    profile.University   = userprofilemodel.University.Trim();
                    profile.College      = userprofilemodel.College.Trim();
                    profile.ModifiedDate = DateTime.Now;
                    profile.ModifiedBy   = user.ID;

                    // delete old profilepic
                    if (userprofilemodel.ProfilePicture != null && profile.ProfilePicture != null)
                    {
                        string   path = Server.MapPath(profile.ProfilePicture);
                        FileInfo file = new FileInfo(path);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                    }

                    // if user upload profile picture then save it and store path in database
                    if (userprofilemodel.ProfilePicture != null)
                    {
                        string filename           = System.IO.Path.GetFileName(userprofilemodel.ProfilePicture.FileName);
                        string fileextension      = System.IO.Path.GetExtension(userprofilemodel.ProfilePicture.FileName);
                        string newfilename        = "DP_" + DateTime.Now.ToString("ddMMyyyy_hhmmss") + fileextension;
                        string profilepicturepath = "~/Members/" + profile.UserID + "/";
                        CreateNewDirectory(profilepicturepath);
                        string path = Path.Combine(Server.MapPath(profilepicturepath), newfilename);
                        profile.ProfilePicture = profilepicturepath + newfilename;
                        userprofilemodel.ProfilePicture.SaveAs(path);
                    }


                    dbobj.Entry(profile).State = EntityState.Modified;
                    dbobj.SaveChanges();

                    user.FirstName          = userprofilemodel.FirstName.Trim();
                    user.LastName           = userprofilemodel.LastName.Trim();
                    dbobj.Entry(user).State = EntityState.Modified;
                    dbobj.SaveChanges();
                }
                // new userprofile
                else
                {
                    UserProfileDetail userprofile = new UserProfileDetail();

                    userprofile.UserID       = user.ID;
                    userprofile.DOB          = userprofilemodel.DOB;
                    userprofile.Gender       = userprofilemodel.Gender;
                    userprofile.CountryCode  = userprofilemodel.CountryCode.Trim();
                    userprofile.PhoneNumber  = userprofilemodel.PhoneNumber.Trim();
                    userprofile.AddressLine1 = userprofilemodel.AddressLine1.Trim();
                    userprofile.AddressLine2 = userprofilemodel.AddressLine2.Trim();
                    userprofile.City         = userprofilemodel.City.Trim();
                    userprofile.State        = userprofilemodel.State.Trim();
                    userprofile.ZipCode      = userprofilemodel.ZipCode.Trim();
                    userprofile.Country      = userprofilemodel.Country.Trim();
                    userprofile.University   = userprofilemodel.University.Trim();
                    userprofile.College      = userprofilemodel.College.Trim();
                    userprofile.CreatedDate  = DateTime.Now;
                    userprofile.CreatedBy    = user.ID;


                    if (userprofilemodel.ProfilePicture != null)
                    {
                        string filename           = System.IO.Path.GetFileName(userprofilemodel.ProfilePicture.FileName);
                        string fileextension      = System.IO.Path.GetExtension(userprofilemodel.ProfilePicture.FileName);
                        string newfilename        = "DP_" + DateTime.Now.ToString("ddMMyyyy_hhmmss") + fileextension;
                        string profilepicturepath = "~/Members/" + userprofile.UserID + "/";
                        CreateNewDirectory(profilepicturepath);
                        string path = Path.Combine(Server.MapPath(profilepicturepath), newfilename);
                        userprofile.ProfilePicture = profilepicturepath + newfilename;
                        userprofilemodel.ProfilePicture.SaveAs(path);
                    }

                    dbobj.UserProfileDetail.Add(userprofile);
                    dbobj.SaveChanges();

                    user.FirstName          = userprofilemodel.FirstName.Trim();
                    user.LastName           = userprofilemodel.LastName.Trim();
                    dbobj.Entry(user).State = EntityState.Modified;
                    dbobj.SaveChanges();
                }

                return(RedirectToAction("SearchNotes", "SearchNotes"));
            }

            //for invalid ModelState
            else
            {
                userprofilemodel.CountryList = dbobj.Countries.Where(x => x.IsActive == true).ToList();
                userprofilemodel.GenderList  = dbobj.ReferenceData.Where(x => x.RefCategory == "Gender" && x.IsActive == true).ToList();
                return(View(userprofilemodel));
            }
        }
        public ActionResult AddReview(NotesReview notereview)
        {
            // check if comment is null or not
            if (String.IsNullOrEmpty(notereview.Comments))
            {
                return(RedirectToAction("MyDownloads"));
            }

            // check if rating is between 1 to 5
            if (notereview.Ratings < 1 || notereview.Ratings > 5)
            {
                return(RedirectToAction("MyDownloads"));
            }

            // get Download object for check if user is downloaded note or not
            var notedownloaded = dobj.Downloads.Where(x => x.ID == notereview.AgainstDownloadsID && x.IsAttachmentDownloaded == true).FirstOrDefault();

            // user can provide notereview after downloading the note
            if (notedownloaded != null)
            {
                var user = dobj.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

                var alreadyprovidereview = dobj.NotesReview.Where(x => x.AgainstDownloadsID == notereview.AgainstDownloadsID && x.IsActive == true).FirstOrDefault();

                // if user not provide notereview then add notereview
                if (alreadyprovidereview == null)
                {
                    NotesReview review = new NotesReview();

                    review.NoteID             = notereview.NoteID;
                    review.AgainstDownloadsID = notereview.AgainstDownloadsID;
                    review.ReviewedByID       = user.ID;
                    review.Ratings            = notereview.Ratings;
                    review.Comments           = notereview.Comments;
                    review.CreatedDate        = DateTime.Now;
                    review.CreatedBy          = user.ID;
                    review.IsActive           = true;

                    dobj.NotesReview.Add(review);
                    dobj.SaveChanges();

                    return(RedirectToAction("MyDownloads"));
                }

                // edit previous notereview
                else
                {
                    alreadyprovidereview.Ratings      = notereview.Ratings;
                    alreadyprovidereview.Comments     = notereview.Comments;
                    alreadyprovidereview.ModifiedDate = DateTime.Now;
                    alreadyprovidereview.ModifiedBy   = user.ID;

                    // update and save notereview
                    dobj.Entry(alreadyprovidereview).State = EntityState.Modified;
                    dobj.SaveChanges();

                    return(RedirectToAction("MyDownloads"));
                }
            }
            return(RedirectToAction("MyDownloads"));
        }
        public ActionResult AddNotes(AddNotes add, string command)
        {
            if (add.UploadNotes[0] == null)
            {
                ModelState.AddModelError("UploadNotes", "This field is required");
                add.NoteCategoryList = dobj.NoteCategories.Where(x => x.IsActive == true).ToList();
                add.NoteTypeList     = dobj.NoteTypes.Where(x => x.IsActive == true).ToList();
                add.CountryList      = dobj.Countries.Where(x => x.IsActive == true).ToList();
                return(View(add));
            }

            if (add.IsPaid == true && add.NotesPreview == null)
            {
                ModelState.AddModelError("NotesPreview", "This field is required if selling type is paid");
                add.NoteCategoryList = dobj.NoteCategories.Where(x => x.IsActive == true).ToList();
                add.NoteTypeList     = dobj.NoteTypes.Where(x => x.IsActive == true).ToList();
                add.CountryList      = dobj.Countries.Where(x => x.IsActive == true).ToList();
                return(View(add));
            }
            foreach (HttpPostedFileBase file in add.UploadNotes)
            {
                if (!System.IO.Path.GetExtension(file.FileName).Equals(".pdf"))
                {
                    ModelState.AddModelError("UploadNotes", "Only PDF Format is allowed");
                    add.NoteCategoryList = dobj.NoteCategories.Where(x => x.IsActive == true).ToList();
                    add.NoteTypeList     = dobj.NoteTypes.Where(x => x.IsActive == true).ToList();
                    add.CountryList      = dobj.Countries.Where(x => x.IsActive == true).ToList();
                    return(View(add));
                }
            }
            if (ModelState.IsValid)
            {
                NoteDetail sellnote = new NoteDetail();

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

                sellnote.SellerID       = user.ID;
                sellnote.Title          = add.Title;
                sellnote.Status         = command == "Save" ? 6 : 7;
                sellnote.Category       = add.Category;
                sellnote.NoteType       = add.NoteType;
                sellnote.NumberofPages  = add.NumberofPages;
                sellnote.Description    = add.Description;
                sellnote.UniversityName = add.UniversityName;
                sellnote.Country        = add.Country;
                sellnote.Course         = add.Course;
                sellnote.CourseCode     = add.CourseCode;
                sellnote.Professor      = add.Professor;
                sellnote.IsPaid         = add.IsPaid;
                if (sellnote.IsPaid)
                {
                    sellnote.SellingPrice = add.SellingPrice;
                }
                else
                {
                    sellnote.SellingPrice = 0;
                }

                if (sellnote.Status == 7)
                {
                    string sellername = user.FirstName + " " + user.LastName;
                    PublishNoteRequestmail(sellnote.Title, sellername);
                }


                sellnote.CreatedDate = DateTime.Now;
                sellnote.CreatedBy   = user.ID;
                sellnote.IsActive    = true;

                dobj.NoteDetail.Add(sellnote);
                dobj.SaveChanges();

                sellnote = dobj.NoteDetail.Find(sellnote.ID);
                if (add.DisplayPicture != null)
                {
                    string displaypicturefilename = System.IO.Path.GetFileName(add.DisplayPicture.FileName);
                    string displaypicturepath     = "~/Members/" + user.ID + "/" + sellnote.ID + "/";
                    NewDirectory(displaypicturepath);
                    string displaypicturefilepath = Path.Combine(Server.MapPath(displaypicturepath), displaypicturefilename);
                    sellnote.DisplayPicture = displaypicturepath + displaypicturefilename;
                    add.DisplayPicture.SaveAs(displaypicturefilepath);
                }

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

                dobj.NoteDetail.Attach(sellnote);
                dobj.Entry(sellnote).Property(x => x.DisplayPicture).IsModified = true;
                dobj.Entry(sellnote).Property(x => x.NotesPreview).IsModified   = true;
                dobj.SaveChanges();

                foreach (HttpPostedFileBase file in add.UploadNotes)
                {
                    if (file != null)
                    {
                        string notesattachementfilename = System.IO.Path.GetFileName(file.FileName);
                        string notesattachementpath     = "~/Members/" + user.ID + "/" + sellnote.ID + "/Attachements/";
                        NewDirectory(notesattachementpath);
                        string notesattachementfilepath = Path.Combine(Server.MapPath(notesattachementpath), notesattachementfilename);
                        file.SaveAs(notesattachementfilepath);

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

                        dobj.NotesAttachments.Add(notesattachements);
                        dobj.SaveChanges();
                    }
                }

                return(RedirectToAction("Dashboard", "SellNotes"));
            }
            else
            {
                AddNotes viewModel = new AddNotes
                {
                    NoteCategoryList = dobj.NoteCategories.Where(x => x.IsActive == true).ToList(),
                    NoteTypeList     = dobj.NoteTypes.Where(x => x.IsActive == true).ToList(),
                    CountryList      = dobj.Countries.Where(x => x.IsActive == true).ToList()
                };

                return(View(viewModel));
            }
        }