public IActionResult AddForm(BookVM book)
        {
            book.genreList  = _genreRepo.GetAllGenres();
            book.authorList = _authorRepo.GetAllAuthors();

            return(View("AddForm", book));
        }
        public Book UpdateBookById(int bookId, BookVM book)
        {
            var _book = _context.Books.FirstOrDefault(b => b.Id == bookId);

            if (_book != null)
            {
                _book.Title       = book.Title;
                _book.Description = book.Description;
                _book.IsRead      = book.IsRead;
                _book.DateRead    = book.IsRead ? book.DateRead.Value : null;
                _book.Rate        = book.IsRead ? book.Rate.Value : null;
                _book.Genre       = book.Genre;
                _book.CoverUrl    = book.CoverUrl;
                _book.DateAdded   = DateTime.Now;

                _context.SaveChanges();
            }
            //foreach (var item in book.AutherIds)
            //{
            //    var book_auther = new Book_Author()
            //    {
            //        BookId = _book.Id,
            //        AuthorId = item,
            //    };
            //    _context.Books_Authors.Add(book_auther);
            //    _context.SaveChanges();

            //}
            return(_book);
        }
Beispiel #3
0
        public void AddBook(BookVM book)
        {
            var _book = new Book
            {
                Title       = book.Title,
                Description = book.Description,
                IsRead      = book.IsRead,
                DateRead    = book.IsRead ? book.DateRead : null,
                Rate        = book.IsRead ? book.Rate : null,
                Genre       = book.Genre,
                CoverUrl    = book.CoverUrl,
                DateAdded   = DateTime.Now,
                PublisherId = book.PublisherId
            };

            _context.Books.Add(_book);
            _context.SaveChanges();

            // As one book can have multiple authors
            // So after adding a new book
            // We need to add entries in BookAuthor table
            // To maintain effect to many relationship
            foreach (var id in book.AuthorIds)
            {
                var _bookAuthor = new BookAuthor
                {
                    BookId   = _book.Id,
                    AuthorId = id
                };
                _context.Add(_bookAuthor);
            }

            _context.SaveChanges();
        }
Beispiel #4
0
        public ActionResult Create(BookVM item)
        {
            if (Session["loggedUser"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            if (!ModelState.IsValid)
            {
                return(View(item));
            }

            Service1Client service = new Service1Client();

            BookDTO book = new BookDTO()
            {
                Title       = item.Title,
                bookAuthor  = service.GetAuthorById(item.AuthorId),
                bookGenre   = service.GetGenreById(item.GenreId),
                Description = item.Description,
                DateAdded   = DateTime.UtcNow,
                Price       = item.Price,
                Rating      = item.Rating
            };

            service.PostBook(book);

            return(RedirectToAction("Index", "Book"));
        }
Beispiel #5
0
        public ActionResult Edit(int Id)
        {
            if (Session["loggedUser"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            Service1Client service = new Service1Client();

            BookDTO   item   = service.GetBookById(Id);
            AuthorDTO author = service.GetAuthorById(item.bookAuthor.Id);
            GenreDTO  genre  = service.GetGenreById(item.bookGenre.Id);

            BookVM book = new BookVM()
            {
                Id          = item.Id,
                Title       = item.Title,
                AuthorId    = item.bookAuthor.Id,
                GenreId     = item.bookGenre.Id,
                Description = item.Description,
                DateAdded   = item.DateAdded,
                Price       = item.Price,
                Rating      = item.Rating
            };

            return(View(book));
        }
Beispiel #6
0
        public IActionResult Details(int?id)
        {
            BookVM obj = new BookVM();

            if (id == null) // New
            {
                return(View(obj));
            }
            else // Edit
            {
                // Eager loading
                obj.Book = db.Books
                           .Include(x => x.BookDetail)
                           .FirstOrDefault(u => u.Book_Id == id);

                //obj.Book.BookDetail = db.BookDetails.FirstOrDefault(x => x.BookDetail_Id == obj.Book.BookDetail_Id);

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

                return(View(obj));
            }
        }
        public IActionResult Update(BookVM book)
        {
            if (ModelState.IsValid)
            {
                // if the image file is new updated
                String imagePath = _bookrepo.GetById(book.books.id).image_path;

                // if new image is updated
                if (book.image != null)
                {
                    // this class contains the function that handles the files
                    FileHandling fileHandling = new FileHandling(_webHostEnvironment);
                    imagePath = fileHandling.fileUpload(book.image, "books");
                }


                book.books.image_path = imagePath;
                _bookrepo.UpdateBook(book.books);
                return(RedirectToAction("Table", book));
            }
            else
            {
                book.fileError  = "Please Upload a Image";
                book.genreList  = _genreRepo.GetAllGenres();
                book.authorList = _authorRepo.GetAllAuthors();

                return(View("UpdateForm", book));
            }
        }
        public IActionResult Upsert(int?id)
        {
            /*Create a viewModel under BookStoreModels folder inside ViewModels folder. This view is
             * custom for this Upsert action method*/
            BookVM bookVM = new BookVM() //Instance of Book view model(not Book) with its properties .
            {
                Book         = new Book(),
                CategoryList = _unitOfWork.Category.GetAll().Select(i => new SelectListItem
                {
                    Text  = i.Name, //Text property of SelectListItem dropdown
                    Value = i.Id.ToString()
                }),
                CoverTypeList = _unitOfWork.CoverType.GetAll().Select(i => new SelectListItem
                {
                    Text  = i.Name,
                    Value = i.Id.ToString()
                })
            };

            if (id == null) //For creating new book
            {
                return(View(bookVM));
            }

            //for edit
            bookVM.Book = _unitOfWork.Book.Get(id.GetValueOrDefault());
            if (bookVM.Book == null)
            {
                return(NotFound());
            }
            return(View(bookVM));
        }
Beispiel #9
0
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Book book = _db.Books.Include(b => b.BookAuthors).ThenInclude(ba => ba.Author).Include(b => b.Publisher).Include(b => b.BookCategories).ThenInclude(bc => bc.Category).Include(b => b.BookFeature).FirstOrDefault(b => b.Id == id);

            if (book == null)
            {
                return(NotFound());
            }
            List <Author>    authors    = _db.Authors.ToList();
            List <Category>  categories = _db.Categories.ToList();
            List <Publisher> publishers = _db.Publishers.ToList();
            BookVM           model      = new BookVM
            {
                Book       = book,
                Authors    = authors,
                Categories = categories,
                Publishers = publishers
            };

            return(View(model));
        }
Beispiel #10
0
 private void DeleteAuthors(BookVM book)
 {
     using (var bookRepo = BCContext.Resolver.Resolve <IBookRepository>(BCContext.DbContext))
     {
         bookRepo.DeleteAuthors(book.Id);
     }
 }
        public ActionResult New()
        {
            var model = new BookVM();

            ViewBag.PageUrl = this.ControllerContext.RouteData.Values["controller"].ToString();
            return(View("NewOrEdit", model));
        }
Beispiel #12
0
        public void AddBookWithAuthors(BookVM book)
        {
            var _book = new Book()
            {
                Title       = book.Title,
                Description = book.Description,
                IsRead      = book.IsRead,
                DateRead    = book.IsRead ? book.DateRead.Value : null,
                Rate        = book.IsRead ? book.Rate.Value : null,
                Genre       = book.Genre,
                CoverURL    = book.CoverURL,
                DateAdded   = DateTime.Now,
                PublisherId = book.PublisherId
            };

            _context.Books.Add(_book);
            _context.SaveChanges();

            foreach (var id in book.AuthorsId)
            {
                var _book_author = new Book_Author()
                {
                    BookId   = _book.Id,
                    AuthorId = id
                };

                _context.Books_Authors.Add(_book_author);
                _context.SaveChanges();
            }
        }
        public ActionResult Archiwum()
        {
            var userId = (Int32)(Session["adminID"]);

            BorrowingVM vm = new BorrowingVM();
            BookVM      bo = new BookVM();

            var list = from b in vm.Get_list()
                       join k in bo.Get_list() on b.BookID equals k.BookID
                       where b.ReaderID == userId
                       orderby b.BorrowID descending
                       select new Your_borrow
            {
                Borrow_date = b.Borrow_date,
                Return_date = b.Return_date,
                Returned    = b.Returned,
                Title       = k.Title
            };

            if (list == null)
            {
                ViewBag.Archiwum = "Nic jeszcze nie zostało wypożyczone."; // TODO odsłużyć w widoku + wyświetlanie listy
            }
            else
            {
                ViewBag.borrow = list;
            }

            return(View());
        }
Beispiel #14
0
        public IActionResult Upsert(int?id)
        {
            BookVM obj = new BookVM();

            obj.PublisherList = db.Publishers.Select(i => new SelectListItem
            {
                Text  = i.Name,
                Value = i.Publisher_Id.ToString()
            });

            if (id == null) // New
            {
                return(View(obj));
            }
            else // Edit
            {
                obj.Book = db.Books.FirstOrDefault(u => u.Book_Id == id);

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

                return(View(obj));
            }
        }
Beispiel #15
0
        public IActionResult Upsert(int?id)
        {
            var book = new BookVM();

            book.PublisherList = _db.Publishers
                                 .Select(p => new SelectListItem
            {
                Text  = p.Name,
                Value = p.Publisher_Id.ToString()
            })
                                 .ToList();

            if (id == null)
            {
                return(View(book));
            }

            book.Book = _db.Books.FirstOrDefault(b => b.Book_Id == id);

            if (book.Book == null)
            {
                return(NotFound());
            }

            return(View(book));
        }
 // GET: Book
 public ActionResult Index(BookVM bookVM = null)
 {
     Session["filter"] = false;
     bookVM.Hotels = HotelManager.GetHotelsByDateLocationAndNbPerson(bookVM.Checkin, bookVM.Checkout, bookVM.Location, bookVM.NbPerson, 0, 5, null, null);
     Session["bookVM"] = bookVM;
     return View(bookVM);
 }
Beispiel #17
0
 public AllBooks(BookVM bookVM_arg)
 {
     bookVM = new BookVM();
     InitializeComponent();
     bookVM      = bookVM_arg;
     DataContext = bookVM;
 }
        public IActionResult Create(BookVM vm)
        {
            //Disable validation on Authors field
            foreach (var value in ModelState.Keys)
            {
                if (value.StartsWith("Authors"))
                {
                    ModelState.Remove(value);
                }
            }


            List <string> validationMessages = new List <string>();

            if (!ModelState.IsValid)
            {
                foreach (var value in ModelState.Values)
                {
                    foreach (var error in value.Errors)
                    {
                        validationMessages.Add(error.ErrorMessage);
                    }
                }
                return(GetBaseResponse(true, "Server-side validation fails. Status = " + ModelState.ValidationState, null, validationMessages));
            }
            using (var service = this.CurrentContext.Factory.GetService <IBookService>(CurrentContext.RootContext))
            {
                service.Create(vm);
            }

            return(GetBaseResponse(false, "Success"));
        }
Beispiel #19
0
        public ActionResult Edit(BookVM model, HttpPostedFileBase file)
        {
            Book mevcut = _db.Books.Find(model.Id);

            if (file != null)
            {
                file.SaveAs(Server.MapPath("~/Images/") + file.FileName);
                mevcut.ImagePath = "/Images/" + file.FileName;
            }
            if (ModelState.IsValid)
            {
                mevcut.Name   = model.Name;
                mevcut.Author = model.Author;
                mevcut.Page   = model.Page;
                mevcut.Count  = model.Count;
                mevcut.ISBN   = model.ISBN;


                mevcut.UpdatedDate = DateTime.Now;
                mevcut.IsActive    = model.IsActive;

                if (mevcut.Count > 0)
                {
                    mevcut.IsActive = true;
                }

                _db.SaveChanges();
                return(RedirectToAction("Index", "Book"));
            }
            else
            {
                return(View(model));
            }
        }
        public void AddBookWithAuthors(BookVM book)
        {
            var _book = new LibBook()
            {
                Book_Title  = book.Book_Title,
                Description = book.Description,
                Edition     = book.Edition,
                isRead      = book.isRead,
                readTime    = book.isRead ? book.readTime.Value : null,
                Genre       = book.Genre,
                addedDate   = DateTime.Now,
                PublisherId = book.PublisherId
            };

            _context.LibBook.Add(_book);
            _context.SaveChanges();

            foreach (var item in book.Authorids)
            {
                var _book_author = new Book_Author()
                {
                    BookId   = _book.BookId,
                    AuthorId = item
                };
                _context.Book_Authors.Add(_book_author);
                _context.SaveChanges();
            }
        }
Beispiel #21
0
        public BookVM Update(BookVM book)
        {
            var model = converter.Parse(book);
            var vm    = converter.Parse(repo.Update(model));

            return(vm);
        }
Beispiel #22
0
 public int Add(BookVM book)
 {
     dbContext.Books.FromSql("");
     this.dbContext.Books.Add(book);
     dbContext.SaveChanges();
     return(book.Bookid);
 }
Beispiel #23
0
 private void UpdateSelectedItem(BookVM newBook)
 {
     if (newBook != null)
     {
         SelectedBookItem = books.Contains(newBook) ? newBook: null;
     }
 }
Beispiel #24
0
        public async Task <ResultModel> Update(BookVM model)
        {
            try
            {
                var entity = await _appContext.Books.FindAsync(model.Id);

                if (entity == null)
                {
                    return(new ResultModel {
                        Result = false, Message = "No Record Found!!"
                    });
                }

                entity.Name     = model.Name;
                entity.UpdateAt = DateTime.Now;
                _appContext.SaveChanges();
                return(new ResultModel {
                    Result = true, Message = $"{model.Name} is Updated successfully", Id = entity.Id
                });
            }
            catch (Exception e)
            {
                return(new ResultModel {
                    Result = false, Message = "Something wrong!!"
                });
            }
        }
Beispiel #25
0
        private void AddLinks(BookVM book)
        {
            var path = "api/v1/book/" + book.Id;

            book.Links.Add(new HyperMediaLink("GET", path, "self", "application/json"));
            book.Links.Add(new HyperMediaLink("PUT", path, "update", "application/json"));
            book.Links.Add(new HyperMediaLink("DELETE", path, "delete", "application/json"));
        }
        public IActionResult Order(Book book)
        {
            BookVM bookVM = new BookVM();

            bookVM.Book      = bookService.GetById(book.ID);
            bookVM.Penalties = penaltyService.GetActive();
            return(View(bookVM));
        }
Beispiel #27
0
        public ActionResult DeleteConfirmed(int id)
        {
            BookVM book = db.Books.Find(id);

            db.Books.Remove(book);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #28
0
 public MainWindow()
 {
     InitializeComponent();
     bookVM       = new BookVM();
     DataContext  = bookVM;
     this.Loaded += MainWindow_Loaded;
     this.Closed += MainWindow_Closed;
 }
Beispiel #29
0
 public ActionResult <ResponseVM> Update([FromBody] BookVM bookVM)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Something went wrong!"));
     }
     return(bookService.Update(bookVM));
 }
 public JsonResult Get(int id)
 {
     using (var service = this.CurrentContext.Factory.GetService <IBookService>(CurrentContext.RootContext))
     {
         BookVM viewModel = service.GetById(id);
         return(new JsonResult(viewModel));
     }
 }