示例#1
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"));
        }
示例#3
0
        public ActionResult SignUp(Models.Users model)
        {
            if (ModelState.IsValid)
            {
                var isExist = IsEmailExist(model.EmailID);
                if (isExist)
                {
                    ModelState.AddModelError("EmailID", "Email already exist");
                    return(View(model));
                }

                Context.Users obj = new Context.Users();
                obj.RoleID          = 3;
                obj.FirstName       = model.FirstName;
                obj.LastName        = model.LastName;
                obj.EmailID         = model.EmailID;
                obj.Password        = model.Password;
                obj.IsEmailVerified = model.IsEmailVerified;
                obj.IsActive        = true;
                obj.CreatedDate     = DateTime.Now;
                obj.SecretCode      = Guid.NewGuid();

                dbobj.Users.Add(obj);
                dbobj.SaveChanges();
                SendVerificationLinkEmail(model.EmailID, model.FirstName, obj.SecretCode.ToString());
                TempData["Success"] = "Your account has been created.";
            }

            ModelState.Clear();
            return(RedirectToAction("SignUp"));
        }
示例#4
0
        public ActionResult AllowDownload(int id)
        {
            NotesMarketPlace.Context.Users user = dobj.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

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

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


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

                AllowDownloadTemplate(download, user);

                return(RedirectToAction("BuyerRequest"));
            }
            else
            {
                return(RedirectToAction("BuyerRequest"));
            }
        }
        public ActionResult DeleteSpamReport(int id)
        {
            var spamreport = dobj.SpamReport.Where(x => x.ID == id).FirstOrDefault();

            if (spamreport == null)
            {
                return(HttpNotFound());
            }
            dobj.SpamReport.Remove(spamreport);
            dobj.SaveChanges();

            return(RedirectToAction("SpamReport"));
        }
        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 ContactUs(Models.ContactUs model)
        {
            if (ModelState.IsValid)
            {
                Context.ContactUs obj = new Context.ContactUs();
                obj.FullName = model.FullName;
                obj.EmailID  = model.EmailID;
                obj.Subjects = model.Subjects;
                obj.Comments = model.Comments;

                dobj.ContactUs.Add(obj);
                SendEmailToAdmin(obj);
                dobj.SaveChanges();
                ModelState.Clear();
                return(RedirectToAction("ContactUs"));
            }
            else
            {
                return(View(model));
            }
        }
        public ActionResult CloneNote(int noteid)
        {
            // logged in user
            var user = dobj.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            //get id of rejected notes
            var rejectednote = dobj.NoteDetail.Find(noteid);

            // creare clone of note
            NoteDetail clonenote = new NoteDetail();

            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;

            // save note in database
            dobj.NoteDetail.Add(clonenote);
            dobj.SaveChanges();

            // get clonenote
            clonenote = dobj.NoteDetail.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));

                FileInfo file = new FileInfo(rejectednotefilepath);

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

                clonenote.DisplayPicture = Path.Combine(clonenotefilepath, Path.GetFileName(rejectednotefilepath));
                dobj.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));

                FileInfo file = new FileInfo(rejectednotefilepath);

                Directory.CreateDirectory(filepath);

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

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

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

                dobj.NotesAttachments.Add(attachement);
                dobj.SaveChanges();
            }
            return(RedirectToAction("Dashboard", "SellNotes"));
        }
示例#9
0
        public ActionResult AddCategory(AddCategory obj)
        {
            if (ModelState.IsValid)
            {
                var            user         = dobj.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();
                NoteCategories noteCategory = new NoteCategories
                {
                    Name        = obj.Name.Trim(),
                    Description = obj.Description.Trim(),
                    CreatedDate = DateTime.Now,
                    CreatedBy   = user.ID,
                    IsActive    = true
                };

                dobj.NoteCategories.Add(noteCategory);
                dobj.SaveChanges();

                return(RedirectToAction("ManageCategory"));
            }
            else
            {
                return(View(obj));
            }
        }
        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));
            }
        }