Esempio n. 1
0
        /// <summary>
        /// Add a new book to database.
        /// </summary>
        /// <param name="model">The new book.</param>
        /// <returns>The new book.</returns>
        public static Book Add(Book model)
        {
            Database db = new Database();

            var @in = Mapper.Map<BookDTO>(model);

            var result = db.BookEntity.Add(@in);

            var @out = Mapper.Map<Book>(result);

            return @out;
        }
        public ActionResult Create()
        {
            var _book = new Book();
            var _categories = Category.Get();

            var book = Mapper.Map<BookModel>(_book);
            book.Number = null;
            var categories = Mapper.Map<CategoryModel[]>(_categories);

            var view = new BookEditContainer { Book = book, Categories = categories };

            return View("edit", view);
        }
Esempio n. 3
0
        /// <summary>
        /// Add or update a book.
        /// </summary>
        /// <param name="model">The book.</param>
        /// <returns>The book.</returns>
        public static Book Set(Book model)
        {
            var book = Get(model.Id);
            model.Id = book.Id;

            if (book.Id == 0)
                return Book.Add(model);
            else
                return Book.Update(model);
        }