/// <summary> /// add purchase details to the purchaseddetails table /// </summary> /// <param name="detailsobj">purchase object</param> /// <returns>true or false on success or failure</returns> public bool PurchaseDocumentDAL(PurchasedDetails detailsobj) { DbParameter p2 = DBHelper.CreateParameter("@userID", detailsobj.UserID); DbParameter p1 = DBHelper.CreateParameter("@docID", detailsobj.DocumentID); DbParameter p3 = DBHelper.CreateParameter("@purchaseDate", detailsobj.PurchasedDate); commandObj = DBHelper.CreateCommand("AddPurchaseDetails", CommandType.StoredProcedure, p1, p2, p3); try { int rowsAffect = DBHelper.ExecuteNonQuery(commandObj); return(rowsAffect > 0 ? true : false); } catch (DbException ex) { ELibraryException exceptionObj = new ELibraryException("Unable to Purchase Document", ex); throw exceptionObj; } catch (ELibraryException ex) { throw ex; } catch (Exception ex) { throw ex; } }
/// <summary> /// method to add a purchase /// </summary> /// <param name="detailsobj">purchase details object</param> /// <returns>true/false</returns> public bool PurchaseDocumentBL(PurchasedDetails detailsobj) { bool isAdded = false; ELibraryPurchasedDAL pruchaseDALObj = new ELibraryPurchasedDAL(); try { isAdded = pruchaseDALObj.PurchaseDocumentDAL(detailsobj); } catch (ELibraryException ex) { throw ex; } return(isAdded); }
protected void btnpay_Click(object sender, EventArgs e) { PaymentDetails paymentObj = new PaymentDetails(); UserDetails userObj = new UserDetails(); userObj.UserID = Session["UserId"].ToString(); try { paymentObj.CreditCardNumber = txtcreditcard.Text; paymentObj.CreditCardName = txtname.Text; paymentObj.CVV = txtcvv.Text; if (ddlexpmonth.SelectedValue == null) { throw new ELibraryException("enter valid month"); } paymentObj.ExpiryMonth = Convert.ToInt32(ddlexpmonth.SelectedValue); int year; bool isYear = int.TryParse(txtexpyear.Text, out year); if (!isYear) { throw new ELibraryException("Enter Valid Year"); } paymentObj.ExpiryYear = year; ELibraryUserBL userBL = new ELibraryUserBL(); ELibraryPaymentBL payBLObj = new ELibraryPaymentBL(); ELibraryDocumentBL docBLObj = new ELibraryDocumentBL(); if (payBLObj.VerifyPaymentBL(paymentObj)) { if ((bool)Session["Subscribe"]) { userBL.UpdateUserSubscriptionBL(userObj, paymentObj); userObj.UserType = "Subscriber"; if (Session["UserObj"] != null) { UserDetails user = (UserDetails)Session["UserObj"]; user.UserType = "Subscriber"; Session["UserObj"] = user; } } ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Payment successful\nPurchased documents will be in downloads.\nHappy Reading!!')", true); } List <int> docIDList = null; if (Session["DocList"] != null) { docIDList = (List <int>)Session["DocList"]; } if (docIDList != null) { ELibraryPurchasedBL purchaseBL = new ELibraryPurchasedBL(); foreach (int doc in docIDList) { PurchasedDetails purchase = new PurchasedDetails(); purchase.DocumentID = doc; purchase.UserID = userObj.UserID; purchase.PurchasedDate = DateTime.Today; purchaseBL.PurchaseDocumentBL(purchase); } Response.Redirect("Download.aspx"); } else { Response.Redirect("Home.aspx"); } } catch (ELibraryException ex) { ErrorLogging erLog = new ErrorLogging(); erLog.LogError(ex.Message); ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + ex.Message + "')", true); } }