Ejemplo n.º 1
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            Book book = new Book(TitleTextBox.Text, AuthorTextBox.Text, dateTimePicker1.Value);

            try
            {
                bookBL.Add(book);
                MessageBox.Show("Book successfully added");
                Close();
            }
            catch (ArgumentException)
            {
                MessageBox.Show("Fill in empty fields");
            }
        }
Ejemplo n.º 2
0
        public ActionResult Create(AddBookFormVM book)
        {
            ViewBag.Genres    = new SelectList(IBookBL.GetAllGenres(), "GenreID", "GenreName");
            ViewBag.Languages = new SelectList(IBookBL.GetAllLanguages(), "LanguageID", "LanguageName");

            if (ModelState.IsValid)
            {
                var     config  = new MapperConfiguration(cfg => { cfg.CreateMap <AddBookFormVM, Book>(); });
                IMapper iMapper = config.CreateMapper();
                Book    _book   = iMapper.Map <AddBookFormVM, Book>(book);
                _book.UserID = UserController.CurrentUser.UserID;


                ViewBag.Alert = IBookBL.Add(_book);

                if (ViewBag.Alert == null)
                {
                    ViewBag.Message = "Added Successfully";
                    ViewBag.Alert   = null;
                }
            }
            return(View(book));
        }