private BookLoanModel ConvertEntityToModel(BookLoanEntity bookLoanEntity) { BookLoanModel bookLoanModel = _mapper.Map <BookLoanModel>(bookLoanEntity); bookLoanModel.BookKeyId = _bookBusiness.GetBookById(bookLoanEntity.BookId).KeyId; bookLoanModel.ReaderKeyId = _readerBusiness.GetReaderById(bookLoanEntity.ReaderId).KeyId; return(bookLoanModel); }
private void buttonExportToWord_Click(object sender, EventArgs e) { BookLoanModel bloanM = new BookLoanModel(); bookloanDAL bloanD = new bookloanDAL(); bookLoan = bloanD.Select(); Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application(); Document doc = word.Documents.Add(); Microsoft.Office.Interop.Word.Range rng = doc.Range(0, 0); doc.Content.Text = "hello"; doc.Content.Text = "dude"; Table wdTable = doc.Tables.Add(rng, bookLoan.Rows.Count + 1, bookLoan.Columns.Count); wdTable.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleDouble; wdTable.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle; try { doc = word.ActiveDocument; //i is the row index for (int i = 0; i < bookLoan.Rows.Count; i++) { for (int j = 0; j < bookLoan.Columns.Count; j++) { if (i == 0) { wdTable.Cell(i + 1, j + 1).Range.InsertAfter(bookLoan.Columns[j].ToString()); } { wdTable.Cell(i + 2, j + 1).Range.InsertAfter(bookLoan.Rows[i][j].ToString()); } } } if (saveFileDialog1.ShowDialog() == DialogResult.OK) { doc.SaveAs2(saveFileDialog1.FileName); Process.Start("winword.exe", saveFileDialog1.FileName); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { word.Quit(); word = null; doc = null; } }
public bool Insert(BookLoanModel b) { bool isSuccess = false; //create sql connection to connect database SqlConnection conn = new SqlConnection(myConnectionString); try { //write the query to insert into database string sql = "INSERT INTO book_loan (issued_book_id,issued_to_user_id,issued_date,return_date,issued_book_name,issued_user_name,return_status) VALUES(@issued_book_id,@issued_to_user_id,@issued_date,@return_date,@issued_book_name,@issued_user_name,@return_status)"; //create sql command to execute the query SqlCommand cmd = new SqlCommand(sql, conn); //pass the value to sql query cmd.Parameters.AddWithValue("@issued_book_id", b.issued_book_id); cmd.Parameters.AddWithValue("@issued_to_user_id", b.issued_to_user_id); cmd.Parameters.AddWithValue("@issued_date", b.issued_date); cmd.Parameters.AddWithValue("@return_date", b.return_date); cmd.Parameters.AddWithValue("@issued_book_name", b.issued_book_name); cmd.Parameters.AddWithValue("@issued_user_name", b.issued_user_name); cmd.Parameters.AddWithValue("@return_status", b.return_status); //open database connection conn.Open(); //create an integer variable to check whether the query was executed succesfully or not int checkValue = cmd.ExecuteNonQuery(); if (checkValue > 0) { isSuccess = true; userDAL u = new userDAL(); u.Update(b.issued_user_name, countBooksLend(b.issued_user_name)); bookDAL bro = new bookDAL(); bro.Update(b.issued_book_name, b.return_status); } else { isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
public bool Update(BookLoanModel b) { bool isUpdateSuccess = false; //create sql connection SqlConnection conn = new SqlConnection(myConnectionString); try { string sql = "UPDATE book_loan SET issued_book_id=@issued_book_id,issued_to_user_id=@issued_to_user_id,issued_date=@issued_date,return_date=@return_date,issued_book_name=@issued_book_name,return_status=@return_status WHERE id=@id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@issued_book_id", b.issued_book_id); cmd.Parameters.AddWithValue("@issued_to_user_id", b.issued_to_user_id); cmd.Parameters.AddWithValue("@issued_date", b.issued_date); cmd.Parameters.AddWithValue("@return_date", b.return_date); cmd.Parameters.AddWithValue("@id", b.id); cmd.Parameters.AddWithValue("@issued_book_name", b.issued_book_name); cmd.Parameters.AddWithValue("@issued_user_name", b.issued_user_name); cmd.Parameters.AddWithValue("@return_status", b.return_status); conn.Open(); int checkValue = cmd.ExecuteNonQuery(); if (checkValue > 0) { isUpdateSuccess = true; userDAL u = new userDAL(); u.Update(b.issued_user_name, countBooksLend(b.issued_user_name)); bookDAL bro = new bookDAL(); bro.Update(b.issued_book_name, b.return_status); } else { isUpdateSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isUpdateSuccess); }
public List <BookLoanModel> Search(int userID) { List <BookLoanModel> listBook = new List <BookLoanModel>(); //create an sql connection for connecting db SqlConnection conn = new SqlConnection(myConnectionString); //create data table to hold the data from db temporariy in memory DataTable dt = new DataTable(); //main code try { //write the sql query for search operation String sql = "SELECT * FROM book_loan WHERE issued_to_user_id LIKE '%" + userID + "%' AND return_status = '" + 0 + "'"; //create sql command to execute query SqlCommand cmd = new SqlCommand(sql, conn); //create sql data adapter to get data from db SqlDataAdapter adapter = new SqlDataAdapter(cmd); //open connection conn.Open(); //pass data from adapter to datatable adapter.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { BookLoanModel m = new BookLoanModel(); m.issued_book_name = dt.Rows[i]["issued_book_name"].ToString(); m.issued_user_name = dt.Rows[i]["issued_user_name"].ToString(); m.issued_date = DateTime.Parse(dt.Rows[i]["issued_date"].ToString()); m.return_date = DateTime.Parse(dt.Rows[i]["return_date"].ToString()); listBook.Add(m); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(listBook); }
public BookLoanModel Update(BookLoanModel bookLoanModel) { BookLoanEntity bookLoanEntity = _repository.FindByKeyId(bookLoanModel.KeyId); bookLoanEntity.ReturnDate = bookLoanModel.ReturnDate; bookLoanEntity.ReturnFeedback = bookLoanModel.ReturnFeedback; bookLoanEntity = _repository.Update(bookLoanEntity); BookLoanModel bookLoan = _mapper.Map <BookLoanModel>(bookLoanEntity); bookLoan.BookKeyId = bookLoanModel.BookKeyId; bookLoan.ReaderKeyId = bookLoanModel.ReaderKeyId; return(bookLoan); }
public BookLoanModel Insert(BookLoanModel bookLoanModel) { BookLoanEntity bookLoanEntity = _mapper.Map <BookLoanEntity>(bookLoanModel); bookLoanEntity.KeyId = Guid.NewGuid( ); bookLoanEntity.BookId = _bookBusiness.GetIdBookByKeyId(bookLoanModel.BookKeyId); bookLoanEntity.ReaderId = _readerBusiness.GetIdBookByKeyId(bookLoanModel.ReaderKeyId); bookLoanEntity.ReturnDate = null; bookLoanEntity.ReturnFeedback = null; bookLoanEntity = _repository.Insert(bookLoanEntity); BookLoanModel bookLoan = _mapper.Map <BookLoanModel>(bookLoanEntity); bookLoan.BookKeyId = bookLoanModel.BookKeyId; bookLoan.ReaderKeyId = bookLoanModel.ReaderKeyId; return(bookLoan); }
public bool Delete(BookLoanModel b) { bool isDeleteSuccess = false; SqlConnection conn = new SqlConnection(myConnectionString); try { String sql = "DELETE FROM book_loan WHERE id = @id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@id", b.id); conn.Open(); int checkValue = cmd.ExecuteNonQuery(); if (checkValue > 0) { isDeleteSuccess = true; } else { isDeleteSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isDeleteSuccess); }
public async Task <IActionResult> Post([FromBody] BookLoanModel bookLoanModel) { IActionResult result; try { if (_bookLoanServices.Insert(bookLoanModel) != null) { result = Ok( ); } else { result = new StatusCodeResult(500); } } catch (Exception ex) { _logger.LogError(ex, ex.Message); result = new StatusCodeResult(500); } return(result); }
public async Task <IActionResult> GetByKeyId([FromRoute] Guid keyId) { IActionResult result = null; try { BookLoanModel bookLoanModel = _bookLoanServices.GetByKeyId(keyId); if (bookLoanModel != null) { result = Ok(bookLoanModel); } else { result = NoContent( ); } } catch (Exception ex) { _logger.LogError(ex, ex.Message); result = new StatusCodeResult(500); } return(result); }
public IActionResult Create(string memberId, string bookId, DateTime startDate, DateTime endDate) { ObjectId memberOId = new ObjectId(memberId); ObjectId bookOId = new ObjectId(bookId); Book book = BookRepository.GetBookById(bookOId); int copiesRemaining = CheckLoansToCopies.Book(book.Id, book.NumberOfCopies, startDate, endDate); if (copiesRemaining > 0) { Loan loan = CreateLoan(memberOId, book.Id, startDate, endDate); BookLoanRepository.InsertBookLoan(loan); } else if (copiesRemaining <= 0) { string errorMessage = "No availiable copies at that date. Please try an other one"; BookLoanModel bookLoanModel = new BookLoanModel(); bookLoanModel.ErrorMessage = errorMessage; return(View(bookLoanModel)); } return(Redirect("/BookLoan")); }
public BookLoanModel Update(BookLoanModel bookLoanModel) { return(_bookLoanBusiness.Update(bookLoanModel)); }
public BookLoanModel Insert(BookLoanModel bookLoanModel) { return(_bookLoanBusiness.Insert(bookLoanModel)); }
public IActionResult Create() { BookLoanModel bookLoanModel = new BookLoanModel(); return(View(bookLoanModel)); }