예제 #1
0
        /// <summary>
        /// 書籍情報を登録する。
        /// </summary>
        /// <param name="?"></param>
        public void regist(BookInfo bookInfo)
        {
            if (bookInfo == null) {
                throw new NullReferenceException("BookInfo is null");
            }

            // TODO 宣言的トランザクションに対応する。
            DataBaseAccessor accessor = new DataBaseAccessor();
            accessor.open();

            BookEval eval = null;
            // Evalのマスタ存在チェック
            if (bookInfo.EvalType != null) {
                BookEvalDao evalDao = new BookEvalDao(accessor);
                eval = evalDao.findById(bookInfo.EvalType);
                if (eval == null)
                {
                    // TODO Exceptionを確認
                    throw new ApplicationRuntimeException("評価マスタ上に存在しない評価です。");
                }
            }

            // Bookの存在有無チェック
            BookDao bookDao = new BookDao(accessor);
            Book existsBook = bookDao.findByIsbn(bookInfo.Isbn);
            if (existsBook != null)
            {
                throw new ApplicationRuntimeException("この本は既に登録済みです。入力内容をご確認ください");
            }

            // BookEntityの作成
            Book registBook = new Book();
            registBook.BookType = bookInfo.BookType;
            registBook.Title = bookInfo.Title;
            registBook.Isbn = bookInfo.Isbn;
            registBook.Publisher = bookInfo.Publisher;
            registBook.Price = bookInfo.Price;
            registBook.BuyDate = bookInfo.BuyDate;
            registBook.Status = bookInfo.Status;
            registBook.BookEval = eval;
            registBook.Eval = bookInfo.Eval;

            bookDao.insert(registBook);
        }
예제 #2
0
        protected void Regist_Click(object sender, EventArgs e)
        {
            try
            {
                // Service呼び出し用のDto作成
                BookInfo bookInfo = new BookInfo();
                bookInfo.BookType = getBookType();
                bookInfo.Title = trim(title.Text);
                bookInfo.Isbn = trim(isbn.Text);
                bookInfo.Publisher = trim(publisher.Text);
                if (!String.IsNullOrEmpty(price.Text))
                {
                    bookInfo.Price = int.Parse(price.Text);
                }
                bookInfo.BuyDate = buyDate.SelectedDate;
                if (!SystemConstants.ViewLayerConstants.EMPTY_DRPDWN_VALUE.Equals(BookEval.SelectedItem.Value))
                {
                    bookInfo.EvalType = Int64.Parse(BookEval.SelectedItem.Value);
                }
                bookInfo.Eval = trim(eval.Text);

                BookManageService service = new BookManageService();

                service.regist(bookInfo);
                Message.Text = "書籍情報を登録しました";
                Message.ForeColor = System.Drawing.Color.Black;
            }
            catch (ApplicationRuntimeException exception)
            {
                // TODO アスペクトにする。
                Message.Text = exception.Message;
                Message.ForeColor = System.Drawing.Color.Red;
                if (exception.InnerException != null)
                {
                    throw exception.InnerException;
                }
            }
        }