Exemplo n.º 1
0
        public ActionResult Paid_download(int id)
        {
            var user_email = dbobject.tblUsers.Where(m => m.EmailID.Equals(User.Identity.Name)).FirstOrDefault();

            var tblSeller     = dbobject.tblSellerNotes.Where(m => m.ID == id).FirstOrDefault();
            var user_id       = user_email.ID;
            var checkdownload = dbobject.tblDownloads.Where(m => m.NoteID == id && m.Downloader == user_id).FirstOrDefault();

            if (checkdownload != null)
            {
                return(Json(new { success = true, alertMsg = "already downloaded this note." }, JsonRequestBehavior.AllowGet));
            }

            //tblSellerNote tblSeller = dbobj.tblSellerNotes.Find(id).;
            if (tblSeller == null || tblSeller.Status != 9)
            {
                return(HttpNotFound());
            }

            else if (tblSeller != null && tblSeller.Status == 9)
            {
                var    seller      = dbobject.tblUsers.Where(m => m.ID == tblSeller.SellerID).FirstOrDefault();
                string path        = (from sa in dbobject.tblSellerNotesAttachements where sa.NoteID == tblSeller.ID select sa.FilePath).First().ToString();
                string category    = (from c in dbobject.tblNoteCategories where c.ID == tblSeller.Category select c.Name).First().ToString();
                string seller_name = seller.FirstName;
                seller_name += " " + seller.LastName;
                string buyer_name = user_email.FirstName;
                buyer_name += " " + user_email.LastName;
                string buyer_email = seller.EmailID;

                tblDownload obj = new tblDownload();
                obj.NoteID     = tblSeller.ID;
                obj.Seller     = tblSeller.SellerID;
                obj.Downloader = user_id;
                obj.IsSellerHasAllowedDownload = false;
                obj.AttachmentPath             = path;
                obj.IsAttachmentDownloaded     = false;
                obj.IsPaid         = true;
                obj.PurchasedPrice = tblSeller.SellingPrice;
                obj.NoteTitle      = tblSeller.Title;
                obj.NoteCategory   = category;
                obj.CreatedDate    = DateTime.Now;

                dbobject.tblDownloads.Add(obj);

                string subject = buyer_name + " wants to purchase your notes";
                string body    = "Hello" + " " + seller_name + ",<br/><br/>We would like to inform you that, " + buyer_name + " wants to purchase your notes." +
                                 " Please see Buyer Requests tab and allow download access to Buyer if you have received " +
                                 "the payment from him.<br/><br/>Regards,<br/>Notes Marketplace";
                ForgotPass mailer = new ForgotPass();
                mailer.sendMail(subject, body, buyer_email);
                dbobject.SaveChanges();
                ViewBag.Msg = "Request Added";

                return(Json(new { success = true, responseText = seller_name }, JsonRequestBehavior.AllowGet));
                //#codebyChandreshMendapara
            }

            return(Json(new { success = false, responseText = "Error..." }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public ActionResult Free_downLoad(int?id)
        {
            var user_email = dbobject.tblUsers.Where(m => m.EmailID.Equals(User.Identity.Name)).FirstOrDefault();

            var tblSeller = dbobject.tblSellerNotes.Where(m => m.ID == id).FirstOrDefault();
            var user_id   = user_email.ID;

            /* if (id == null)
             * {
             *   return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
             * }
             * else*/
            if (!tblSeller.IsPaid)
            {
                if (tblSeller == null || tblSeller.Status != 9)
                {
                    return(HttpNotFound());
                }

                else if (tblSeller != null && tblSeller.Status == 9)
                {
                    string      path     = (from sa in dbobject.tblSellerNotesAttachements where sa.NoteID == tblSeller.ID select sa.FilePath).First().ToString();
                    string      category = (from c in dbobject.tblNoteCategories where c.ID == tblSeller.Category select c.Name).First().ToString();
                    tblDownload obj      = new tblDownload();
                    obj.NoteID     = tblSeller.ID;
                    obj.Seller     = tblSeller.SellerID;
                    obj.Downloader = user_id;
                    obj.IsSellerHasAllowedDownload = true;
                    obj.AttachmentPath             = path;
                    obj.IsAttachmentDownloaded     = true;
                    obj.IsPaid         = false;
                    obj.PurchasedPrice = tblSeller.SellingPrice;
                    obj.NoteTitle      = tblSeller.Title;
                    obj.NoteCategory   = category;
                    obj.CreatedDate    = DateTime.Now;
                    dbobject.tblDownloads.Add(obj);
                    dbobject.SaveChanges();

                    string file_name = (from sa in dbobject.tblSellerNotesAttachements where sa.NoteID == id select sa.FileName).First().ToString();
                    file_name += ".pdf";
                    byte[] fileBytes = System.IO.File.ReadAllBytes(path);

                    return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, file_name));
                }
            }
            return(HttpNotFound());
        }