Пример #1
0
        private void InsertReview_Click(object sender, EventArgs e)
        {
            var book   = new BookRepository();
            var reader = new ReaderRepository();
            var review = new ReviewRepository();
            var loan   = new LoanRepository();

            var queryCarteId = book.GetBookIdByTitle(boxTitluCarteInsertReview.Text.Trim());

            if (queryCarteId.LongCount() > 0)
            {
                int idCarte = queryCarteId[0].CarteId;

                var queryDateCarteImprumutata = loan.GetLoanIdByBookId(idCarte);
                queryDateCarteImprumutata[0].DataRestituire = DateTime.Now;
                loan.UpdateLoan(queryDateCarteImprumutata[0]);

                var queryDateImprumut    = loan.GetLoanIdByBookId(idCarte);
                var queryCititorImprumut = loan.GetLoanIdByBookId(idCarte);

                if (queryDateImprumut[0].DataRestituire > queryDateImprumut[0].DataScadenta)
                {
                    var queryStareCititor = reader.GetReaderById(queryCititorImprumut[0].CititorId);
                    queryStareCititor[0].Stare = 1;
                    reader.UpdateReader(queryStareCititor[0]);
                }

                REVIEW rev = new REVIEW()
                {
                    Text       = boxTextReviewInsertReview.Text.Trim(),
                    ImprumutId = queryDateImprumut[0].ImprumutId,
                };

                review.InsertReview(rev);
                MessageBox((IntPtr)0, "\nInsert Operation Completed", "Message Box", 0);
            }
            else
            {
                MessageBox((IntPtr)0, "\nCartea nu exista/este imprumutata", "Message Box", 0);
            }

            boxTitluCarteInsertReview.Text = "";
            boxTextReviewInsertReview.Text = "";
        }