Пример #1
0
        public ActionResult Save(BookViewModel book,
                                 [Bind(Prefix = "Image")] HttpPostedFileBase image,
                                 [Bind(Prefix = "ImageChanged")] bool imageChanged)
        {
            if (ModelState.IsValid)
            {
                Book   bookEntity = Mapper.Map <BookViewModel, Book>(book);
                byte[] imageBytes = null;

                if (imageChanged)
                {
                    if (image != null)
                    {
                        imageBytes = Utils.Utils.StreamToArray(image.InputStream);
                    }
                }
                else
                {
                    imageBytes = booksRepository.GetImage(bookEntity.Id);
                }

                bookEntity.Image = imageBytes;

                if (bookEntity.Id > 0)
                {
                    booksRepository.Update(bookEntity);
                }
                else
                {
                    booksRepository.Create(bookEntity);
                }
                return(Json(Mapper.Map <Book, BookViewModel>(bookEntity)));
            }
            return(new JsonValidationError(ModelState));
        }
Пример #2
0
        public void AddBook()
        {
            var book = new Book();

            book.Name  = "First Book";
            book.Price = 145.70M;

            _booksRepository.Create(book);
            _booksRepository.Save();
        }
Пример #3
0
        public async Task <bool> CreateAsync(Book book)
        {
            var dbBook = await _booksRepository.GetByTitleAsync(book.Title);

            if (dbBook == null)
            {
                _booksRepository.Create(book);
                return(true);
            }

            return(false);
        }
        public bool Create(Book book)
        {
            var dbBook = _booksRepository.GetByTitle(book.Title);

            if (dbBook == null)
            {
                _booksRepository.Create(book);
                return(true);
            }

            return(false);
        }
Пример #5
0
        public StatusModel Create(Book book)
        {
            var response = new StatusModel();
            var dbBook   = _booksRepository.GetByTitle(book.Title);

            if (dbBook == null)
            {
                _booksRepository.Create(book);
                response.Message = $"The book with title {book.Title} has been successfully created";
                return(response);
            }
            else
            {
                response.Message       = $"The book with title {book.Title} already exists.";
                response.IsSuccessfull = false;
                return(response);
            }
        }
Пример #6
0
 public Book Create(Book item)
 {
     log.Info <BooksApiController>("Create Book:" + item.ToString());
     booksRepository.Create(item);
     return(item);
 }
Пример #7
0
 public ActionResult Create(BooksStaroseletsEV book)
 {
     repo.Create(book);
     return(RedirectToAction("ListOfBooks"));
 }
Пример #8
0
        public void Create(BookDto bookDto)
        {
            var book = bookDto.ToBook();

            booksRepository.Create(book);
        }
Пример #9
0
 public Book Create(Book book)
 {
     return(_bookRepository.Create(book));
 }