public ActionResult RequestPaidNotes(int noteid)
        {
            // get note
            var       note    = dobj.NoteDetail.Find(noteid);
            int       ID      = noteid;
            NoteStats noteobj = new NoteStats();


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

            // create download object
            Downloads download = new Downloads
            {
                NoteID     = note.ID,
                Seller     = note.SellerID,
                Downloader = user.ID,
                IsSellerHasAllowedDownload = false,
                IsAttachmentDownloaded     = false,
                IsPaid         = note.IsPaid,
                PurchasedPrice = note.SellingPrice,
                NoteTitle      = note.Title,
                NoteCategory   = note.NoteCategories.Name,
                CreatedDate    = DateTime.Now,
                CreatedBy      = user.ID,
            };

            // add,save database
            dobj.Downloads.Add(download);
            dobj.SaveChanges();

            TempData["ShowModal"] = 1;
            //mail
            //Mailforpaid(download, user);

            return(RedirectToAction("NoteDetail", new { id = note.ID }));
        }
        public ActionResult NoteDetail(int id)
        {
            var user = dobj.Users.Where(x => x.EmailID == User.Identity.Name).FirstOrDefault();

            // if logged in user's role is not member then redirect to admin dashboard
            if (User.Identity.IsAuthenticated)
            {
                if (user.RoleID != dobj.UserRole.Where(x => x.Name.ToLower() == "member").Select(x => x.ID).FirstOrDefault())
                {
                    return(RedirectToAction("Dashboard", "Admin"));
                }
            }
            var NoteDetail = dobj.NoteDetail.Where(x => x.ID == id && x.IsActive == true).FirstOrDefault();

            if (NoteDetail == null)
            {
                return(HttpNotFound());
            }
            var seller = dobj.Users.Where(x => x.ID == NoteDetail.SellerID).FirstOrDefault();

            IEnumerable <ReviewsModel> reviews = from review in dobj.NotesReview
                                                 join users in dobj.Users on review.ReviewedByID equals users.ID
                                                 join userprofile in dobj.UserProfileDetail on review.ReviewedByID equals userprofile.UserID
                                                 where review.NoteID == id && review.IsActive == true
                                                 orderby review.Ratings descending
                                                 select new ReviewsModel {
                TblSellerNotesReview = review, TblUser = users, TblUserProfile = userprofile
            };

            var reviewcounts = reviews.Count();

            decimal avgreview = 0;

            if (reviewcounts > 0)
            {
                avgreview = Math.Ceiling((from x in reviews select x.TblSellerNotesReview.Ratings).Average());
            }

            var spams = dobj.SpamReport.Where(x => x.NoteID == id).Count();

            NoteStats notesdetail = new NoteStats();

            if (user != null)
            {
                notesdetail.UserID = user.ID;
            }
            notesdetail.SellerNote      = NoteDetail;
            notesdetail.Seller          = seller.FirstName + " " + seller.LastName;
            notesdetail.Buyer           = user.FirstName;
            notesdetail.NotesReview     = reviews;
            notesdetail.AverageRating   = Convert.ToInt32(avgreview);
            notesdetail.TotalReview     = reviewcounts;
            notesdetail.TotalSpamReport = spams;

            if (User.Identity.IsAuthenticated)
            {
                var request            = dobj.Downloads.Where(x => x.NoteID == id && x.Downloader == user.ID && x.IsSellerHasAllowedDownload == false && x.AttachmentPath == null).FirstOrDefault();
                var allowdownloadnotes = dobj.Downloads.Where(x => x.NoteID == id && x.Downloader == user.ID && x.IsSellerHasAllowedDownload == true && x.AttachmentPath != null).FirstOrDefault();
                if (request == null && allowdownloadnotes == null)
                {
                    notesdetail.NoteRequested = false;
                }
                else
                {
                    notesdetail.NoteRequested = true;
                }

                if (allowdownloadnotes != null && request == null)
                {
                    notesdetail.AllowDownload = true;
                }
                else
                {
                    notesdetail.AllowDownload = false;
                }
            }
            if (User.Identity.IsAuthenticated)
            {
                return(View(notesdetail));
            }
            else
            {
                return(RedirectToAction("Login", "SignUp"));
            }
        }