示例#1
0
        public ActionResult Edit(Guid?id, BookModel model)
        {
            if (model == null || ModelState.IsValid == false)
            {
                if (model == null && id != null)
                {
                    model = AutoMapper.Mapper.Map <BookModel>(_booksRepository.Get(id.Value));
                }
                return(View(model));
            }
            else
            {
                var entity = id != null?_booksRepository.Get(id.Value) : new BookEntity();

                AutoMapper.Mapper.Map(model, entity);

                if (model.Image.Upload != null && model.Image.Upload.ContentLength > 0)
                {
                    var uploadDir = "~/uploads";
                    var filename  = Guid.NewGuid().ToString() + ".jpg";
                    var mapPath   = Server.MapPath(uploadDir);
                    Directory.CreateDirectory(mapPath);
                    var imagePath = Path.Combine(mapPath, filename);
                    var imageUrl  = Path.Combine(uploadDir, filename);
                    model.Image.Upload.SaveAs(imagePath);
                    entity.Image = imageUrl;
                }

                _booksRepository.AddOrUpdate(entity);

                return(View("_ClosePopup"));
            }
        }
示例#2
0
        public BookDTO GetBook(Guid id)
        {
            Book    dbBook  = _booksRepository.Get(id);
            BookDTO bookDTO = new BookDTO()
            {
                Id    = dbBook.Id,
                Title = dbBook.Title,
                Year  = dbBook.Year,
            };

            return(bookDTO);
        }
 public ActionResult Edit(int?id)
 {
     if (id != null)
     {
         ViewBag.publishers = publishers.GetAll();
         ViewBag.authors    = authors.GetAll();
         ViewBag.page       = "Edit";
         return(View("Edit", books.Get((int)id)));
     }
     return(RedirectToAction("List"));
 }
示例#4
0
        public async Task <ActionResult <IList <Books> > > Get()
        {
            var books = await _booksRepository.Get();

            if (books == null)
            {
                return(NotFound());
            }

            Response.Headers.Add("X-Total-Count", new StringValues(books.Count.ToString()));
            Response.Headers.Add("page-size", new StringValues(books.Count.ToString()));

            return(Ok(books));
        }
示例#5
0
        // GET: api/Books/5
        public Book Get(int id)
        {
            BooksRepository booksRepo = new BooksRepository();

            return(booksRepo.Get(id));
        }
 public IEnumerable <Book> Get()
 {
     return(_repo.Get());
 }
示例#7
0
        public BookResponseDTO Get(int bookId)
        {
            var book = _bookRepository.Get(bookId);

            return(book);
        }
示例#8
0
 internal IEnumerable <Book> Get()
 {
     return(_repo.Get());
 }