Example #1
0
        public ActionResult UnPublishNote(FormCollection form)
        {
            int    noteid = Convert.ToInt32(form["noteid"]);
            string remark = form["unpublish-remark"];

            // get user
            var user = _dbcontext.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();
            // get note
            var note = _dbcontext.SellerNotes.Where(x => x.ID == noteid).FirstOrDefault();

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

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

            // update note status
            note.Status       = removedid;
            note.ModifiedBy   = user.UserID;
            note.ModifiedDate = DateTime.Now;

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

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

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

            return(RedirectToAction("Dashboard", "Admin"));
        }
        public ActionResult MakeNoteInReview(int id)
        {
            // get note by id
            var note = _dbcontext.SellerNotes.Where(x => x.ID == id).FirstOrDefault();

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

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

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

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

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

            return(RedirectToAction("NotesUnderReview"));
        }
Example #3
0
        public ActionResult Signup(SignupViewModel signupviewmodel)
        {
            if (ModelState.IsValid)
            {
                //check if email already exists or not
                bool emailalreadyexists = _dbcontext.Users.Any(x => x.EmailID == signupviewmodel.Email);

                if (emailalreadyexists)
                {
                    ModelState.AddModelError("Email", "Email already registered");
                    return(View(signupviewmodel));
                }
                else
                {
                    var memberid = _dbcontext.UserRoles.Where(x => x.Name.ToLower() == "member").Select(x => x.ID).FirstOrDefault();
                    //create user and save into database
                    User user = new User
                    {
                        FirstName   = signupviewmodel.FirstName.Trim(),
                        LastName    = signupviewmodel.LastName.Trim(),
                        EmailID     = signupviewmodel.Email.Trim(),
                        Password    = signupviewmodel.Password.Trim(),
                        CreatedDate = DateTime.Now,
                        RoleID      = memberid,
                        IsActive    = true
                    };

                    // add user in database
                    _dbcontext.Users.Add(user);
                    _dbcontext.SaveChanges();

                    // send date as string format for validate user
                    string date = user.CreatedDate.Value.ToString("ddMMyyyyHHmmss");


                    var request = HttpContext.Request;

                    string baseurl = "https://localhost:" + request.Url.Port;

                    //send email for verification to user
                    BuildEmailVerifyTemplate(baseurl, user, date);


                    //show success message
                    ViewBag.Success = true;

                    // clear modelstate
                    ModelState.Clear();

                    return(View());
                }
            }
            else
            {
                return(View(signupviewmodel));
            }
        }
Example #4
0
        public ActionResult AllowDownload(int id)
        {
            // get logged in user
            User user = _dbcontext.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();
            // get download object by id
            Download download = _dbcontext.Downloads.Find(id);

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

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

                // send mail
                AllowDownloadTemplate(download, user);

                return(RedirectToAction("BuyerRequest"));
            }
            else
            {
                return(RedirectToAction("BuyerRequest"));
            }
        }
Example #5
0
        public ActionResult DeactiveMember(int memberid)
        {
            // get logged in admin
            var user = _dbcontext.Users.Where(x => x.EmailID == User.Identity.Name).First();

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

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

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

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

            // get member's published notes list
            var notelist = _dbcontext.SellerNotes.Where(x => x.SellerID == member.UserID && 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.UserID;

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

            return(RedirectToAction("Members", "AdminMembers"));
        }
Example #6
0
        public ActionResult DeleteSpamReport(int id)
        {
            // get spam report object by id
            var spamreport = _dbcontext.SellerNotesReportedIssues.Where(x => x.ID == id).FirstOrDefault();

            // check if object is null or not
            if (spamreport == null)
            {
                return(HttpNotFound());
            }

            // delete object
            _dbcontext.SellerNotesReportedIssues.Remove(spamreport);
            _dbcontext.SaveChanges();

            return(RedirectToAction("SpamReport"));
        }
Example #7
0
        public ActionResult DeleteDraft(int id)
        {
            // get notes using id
            SellerNote note = _dbcontext.SellerNotes.Where(x => x.ID == id && x.IsActive == true).FirstOrDefault();

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

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

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

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

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

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

            // save changes
            _dbcontext.SaveChanges();

            return(RedirectToAction("Dashboard"));
        }
Example #8
0
        public ActionResult UserProfile(UserProfileViewModel userprofileviewmodel)
        {
            // get logged in user
            var user = _dbcontext.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            // check if ModelState is valid or not
            if (ModelState.IsValid)
            {
                // check if profile picture is not null
                if (userprofileviewmodel.ProfilePicture != null)
                {
                    // get image size and check that it is not more than 10 MB
                    var profilepicsize = userprofileviewmodel.ProfilePicture.ContentLength;
                    if (profilepicsize > 10 * 1024 * 1024)
                    {
                        // if image size is more than 10 MB show error
                        ModelState.AddModelError("ProfilePicture", "Image size limit is 10 MB");
                        userprofileviewmodel.CountryList = _dbcontext.Countries.Where(x => x.IsActive == true).ToList();
                        userprofileviewmodel.GenderList  = _dbcontext.ReferenceDatas.Where(x => x.RefCategory == "Gender" && x.IsActive == true).ToList();
                        return(View(userprofileviewmodel));
                    }
                }

                // get logged in user's profile if exists
                var profile = _dbcontext.UserProfiles.Where(x => x.UserID == user.UserID).FirstOrDefault();

                // if profile is not null then edit userprofile
                if (profile != null)
                {
                    profile.DOB    = userprofileviewmodel.DOB;
                    profile.Gender = userprofileviewmodel.Gender;
                    profile.PhonenumberCountryCode = userprofileviewmodel.PhoneNumberCountryCode.Trim();
                    profile.PhoneNumber            = userprofileviewmodel.PhoneNumber.Trim();
                    profile.AddressLine1           = userprofileviewmodel.AddressLine1.Trim();
                    profile.AddressLine2           = userprofileviewmodel.AddressLine2.Trim();
                    profile.City         = userprofileviewmodel.City.Trim();
                    profile.State        = userprofileviewmodel.State.Trim();
                    profile.ZipCode      = userprofileviewmodel.ZipCode.Trim();
                    profile.Country      = userprofileviewmodel.Country.Trim();
                    profile.University   = userprofileviewmodel.University.Trim();
                    profile.College      = userprofileviewmodel.College.Trim();
                    profile.ModifiedDate = DateTime.Now;
                    profile.ModifiedBy   = user.UserID;

                    // check if loggedin user's profile picture is not null and user upload new profile picture then delete old one
                    if (userprofileviewmodel.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 (userprofileviewmodel.ProfilePicture != null)
                    {
                        string filename           = System.IO.Path.GetFileName(userprofileviewmodel.ProfilePicture.FileName);
                        string fileextension      = System.IO.Path.GetExtension(userprofileviewmodel.ProfilePicture.FileName);
                        string newfilename        = "DP_" + DateTime.Now.ToString("ddMMyyyy_hhmmss") + fileextension;
                        string profilepicturepath = "~/Members/" + profile.UserID + "/";
                        CreateDirectoryIfMissing(profilepicturepath);
                        string path = Path.Combine(Server.MapPath(profilepicturepath), newfilename);
                        profile.ProfilePicture = profilepicturepath + newfilename;
                        userprofileviewmodel.ProfilePicture.SaveAs(path);
                    }

                    // update logged in user's profile and save
                    _dbcontext.Entry(profile).State = EntityState.Modified;
                    _dbcontext.SaveChanges();

                    // update first name and lastname and save
                    user.FirstName = userprofileviewmodel.FirstName.Trim();
                    user.LastName  = userprofileviewmodel.LastName.Trim();
                    _dbcontext.Entry(user).State = EntityState.Modified;
                    _dbcontext.SaveChanges();
                }
                // if profile is null then create user profile
                else
                {
                    // create new userprofile object
                    UserProfile userprofile = new UserProfile();

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

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

                    // save logged in user's profile
                    _dbcontext.UserProfiles.Add(userprofile);
                    _dbcontext.SaveChanges();

                    // save firstname and lastname and save
                    user.FirstName = userprofileviewmodel.FirstName.Trim();
                    user.LastName  = userprofileviewmodel.LastName.Trim();
                    _dbcontext.Entry(user).State = EntityState.Modified;
                    _dbcontext.SaveChanges();
                }

                // if userprofile is created or edited then redirect to search page
                return(RedirectToAction("Search", "SearchNotes"));
            }
            // if ModelState is invalid then redirect to userProfile page
            else
            {
                userprofileviewmodel.CountryList = _dbcontext.Countries.Where(x => x.IsActive == true).ToList();
                userprofileviewmodel.GenderList  = _dbcontext.ReferenceDatas.Where(x => x.RefCategory == "Gender" && x.IsActive == true).ToList();
                return(View(userprofileviewmodel));
            }
        }
        public ActionResult MyProfile(AdminProfileViewModel obj)
        {
            // get logged in user
            var user = _dbcontext.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            // get  logged in user profile
            var userprofile = _dbcontext.UserProfiles.Where(x => x.UserID == user.UserID).FirstOrDefault();

            // check if secondary email is already exists in User or UserProfile table or not
            // if email already exists then give error
            bool secondaryemailalreadyexistsinusers       = _dbcontext.Users.Where(x => x.EmailID == obj.SecondaryEmail).Any();
            bool secondaryemailalreadyexistsinuserprofile = _dbcontext.UserProfiles.Where(x => x.SecondaryEmailAddress == obj.Email && x.UserID != user.UserID).Any();

            if (secondaryemailalreadyexistsinusers || secondaryemailalreadyexistsinuserprofile)
            {
                ModelState.AddModelError("SecondaryEmail", "This email address is already exists");
                obj.CountryCodeList = _dbcontext.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
            userprofile.SecondaryEmailAddress  = obj.SecondaryEmail.Trim();
            userprofile.PhonenumberCountryCode = obj.PhoneNumberCountryCode.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.UserID + "/";
                // 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;
            }

            // update userprofile's data
            userprofile.ModifiedDate = DateTime.Now;
            userprofile.ModifiedBy   = user.UserID;

            // update data and save data in database
            _dbcontext.Entry(user).State        = EntityState.Modified;
            _dbcontext.Entry(userprofile).State = EntityState.Modified;
            _dbcontext.SaveChanges();

            return(RedirectToAction("Dashboard", "Admin"));
        }
        public ActionResult DownloadNotes(int noteid)
        {
            // get note
            var note = _dbcontext.SellerNotes.Find(noteid);

            // if note is not found
            if (note == null)
            {
                return(HttpNotFound());
            }
            // get first object of seller note attachement for attachement
            var noteattachement = _dbcontext.SellerNotesAttachments.Where(x => x.NoteID == note.ID).FirstOrDefault();
            // get logged in user
            var user = _dbcontext.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            // variable for attachement path
            string path;

            // note's seller if and logged in user's id is same it means user want to download his own book
            // then we need to provide downloaded note without entry in download tables
            if (note.SellerID == user.UserID)
            {
                // get attavhement 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
            // downloaded date time is current date time for first time download
            // if user download again then we have to return zip of attachement without changes in data
            if (note.IsPaid == false)
            {
                // if user has already downloaded note then get download object
                var downloadfreenote = _dbcontext.Downloads.Where(x => x.NoteID == noteid && x.Downloader == user.UserID && x.IsSellerHasAllowedDownload == true && x.AttachementPath != null).FirstOrDefault();
                // if user is not downloaded
                if (downloadfreenote == null)
                {
                    // create download object
                    Download download = new Download
                    {
                        NoteID     = note.ID,
                        Seller     = note.SellerID,
                        Downloader = user.UserID,
                        IsSellerHasAllowedDownload = true,
                        AttachementPath            = noteattachement.FilePath,
                        IsAttachementDownload      = true,
                        AttaachementDownloadID     = DateTime.Now,
                        IsPaid         = note.IsPaid,
                        PurchasedPrice = note.SellingPrice,
                        NoteTitle      = note.Title,
                        NoteCategory   = note.NoteCategory.Name,
                        CreatedDate    = DateTime.Now,
                        CreatedBy      = user.UserID,
                    };

                    // save download object in database
                    _dbcontext.Downloads.Add(download);
                    _dbcontext.SaveChanges();

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

                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 paid
            else
            {
                // get download object
                var downloadpaidnote = _dbcontext.Downloads.Where(x => x.NoteID == noteid && x.Downloader == user.UserID && x.IsSellerHasAllowedDownload == true && x.AttachementPath != 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.IsAttachementDownload == false)
                    {
                        downloadpaidnote.IsAttachementDownload = true;
                        downloadpaidnote.ModifiedDate          = DateTime.Now;
                        downloadpaidnote.ModifiedBy            = user.UserID;

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

                    // get attachement path
                    path = Server.MapPath(downloadpaidnote.AttachementPath);

                    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"));
                    }
                }
                return(RedirectToAction("Notes", "SearchNotes", new { id = noteid }));
            }
        }