コード例 #1
0
ファイル: HomeController.cs プロジェクト: Muas/Books
        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
ファイル: DataAccess.cs プロジェクト: Pzk1988/AspBookBase
        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);
        }
コード例 #3
0
 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));
        }
コード例 #6
0
 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());
 }