/// <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> /// returns documents by name /// </summary> /// <param name="name">document name</param> /// <returns>document list</returns> public List <DocumentDetails> ViewDocumentsByName(string name) { string docName = "%" + name + "%"; DbParameter p1 = DBHelper.CreateParameter("@DocumentName", docName); commandObj = DBHelper.CreateCommand("DisplayDocumentsByName", CommandType.StoredProcedure, p1); List <DocumentDetails> documentList = null; try { DataTable table = DBHelper.ExecuteReader(commandObj); if (table.Rows.Count > 0) { documentList = new List <DocumentDetails>(); foreach (DataRow row in table.Rows) { documentList.Add(new DocumentDetails { DocumentID = Convert.ToInt32(row["Document_ID"]), DocumentName = row["Document_Name"].ToString(), Title = row["Title"].ToString(), Author = row["Author"].ToString(), DocumentTypeID = Convert.ToInt32(row["Document_Type_ID"]), DocumentPath = row["Document_Path"].ToString(), UploadDate = Convert.ToDateTime(row["Upload_Date"]), DocumentDescription = row["Document_Description"].ToString(), Price = Convert.ToDouble(row["Price"]) }); } } return(documentList); } catch (DbException ex) { throw ex; } catch (ELibraryException ex) { ELibraryException exceptionObj = new ELibraryException("No documents Available", ex); throw exceptionObj; } }
/// <summary> /// /// </summary> /// <param name="docName"></param> /// <returns></returns> public bool IsValid(string docName) { bool isValid = true; StringBuilder stringBuilderObj = new StringBuilder(); if (docName == "") { stringBuilderObj.AppendLine("Document Name cant be empty"); isValid = false; } if (isValid == false) { ELibraryException exceptionObj = new ELibraryException(stringBuilderObj.ToString()); throw exceptionObj; } return(isValid); }
/// <summary> /// returns all documents /// </summary> /// <returns>document list</returns> public List <DocumentDetails> ViewAllDocumentsDAL() { List <DocumentDetails> documentList = null; commandObj = DBHelper.CreateCommand("DisplayAllDocuments", CommandType.StoredProcedure); try { DataTable table = DBHelper.ExecuteReader(commandObj); if (table.Rows.Count > 0) { documentList = new List <DocumentDetails>(); foreach (DataRow row in table.Rows) { documentList.Add(new DocumentDetails { DocumentID = Convert.ToInt32(row["Document_ID"]), DocumentName = row["Document_Name"].ToString(), Title = row["Title"].ToString(), Author = row["Author"].ToString(), UploadDate = Convert.ToDateTime(row["Upload_Date"]), DocumentDescription = row["Document_Description"].ToString(), Price = Convert.ToDouble(row["Price"]) }); } } } catch (DbException ex) { throw ex; } catch (ELibraryException ex) { ELibraryException exceptionObj = new ELibraryException("No documents Available", ex); throw exceptionObj; } return(documentList); }