Esempio n. 1
0
        public IActionResult Add(BookAddViewModel model)
        {
            var publisher = _publisherService.GetById(model.PublisherId);
            var book      = new Book()
            {
                Name      = model.Name,
                Publisher = publisher
            };

            _bookService.Add(book);

            book.BookAuthors = new List <BookAuthor>();

            foreach (var authorId in model.AuthorIds)
            {
                book.BookAuthors.Add(new BookAuthor()
                {
                    BookId   = book.BookId,
                    AuthorId = authorId
                });
            }
            _bookService.Update(book);

            return(RedirectToAction("Index", "Book"));
        }
Esempio n. 2
0
        // GET: Books/Edit/5
        public ActionResult Edit(int id)
        {
            using (var dbContext = new MvclibraryEntities())
            {
                var b         = dbContext.Books.ToList();
                var editBooks = dbContext.Books.Where(c => c.Id == id).FirstOrDefault();

                var zvm = new BookAddViewModel
                {
                    Id = editBooks.Id,
                    SelectedCategoryId = editBooks.CategoryId.ToString(),
                    Author             = editBooks.Author,
                    ISBN  = editBooks.ISBN,
                    Title = editBooks.Title
                };

                zvm.CategoryList = dbContext.category.ToList().Select(x => new SelectListItem
                {
                    Value = x.Id.ToString(),
                    Text  = x.Name
                });

                return(View(zvm));
            }
        }
Esempio n. 3
0
        public IActionResult Add()
        {
            var model = new BookAddViewModel();

            model.Publishers = GetPublisherSelectListItems();
            model.Authors    = GetAuthorSelectListItems();

            return(View(model));
        }
Esempio n. 4
0
        public ActionResult Add()
        {
            var model = new BookAddViewModel
            {
                Book       = new Book(),
                Categories = _categoryService.GetList().Data
            };

            return(View(model));
        }
Esempio n. 5
0
        public ActionResult Create(BookAddViewModel newBook)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (var dbContext = new MvclibraryEntities())
                    {
                        if (dbContext.Books.Where(b => b.ISBN == newBook.ISBN).FirstOrDefault() != null)
                        {
                            ModelState.AddModelError("BookExist", "Książka o podanym ISBN juz istnieje");

                            var s = dbContext.category.ToList();

                            newBook.CategoryList = s.Select(x => new SelectListItem
                            {
                                Value = x.Id.ToString(),
                                Text  = x.Name
                            });
                            return(View(newBook));
                        }
                        var book = new Books
                        {
                            Author       = newBook.Author,
                            Status       = "Dostepna",
                            Title        = newBook.Title,
                            ISBN         = newBook.ISBN,
                            CategoryId   = int.Parse(newBook.SelectedCategoryId),
                            DateCreatead = DateTime.Now
                        };
                        dbContext.Entry(book).State = EntityState.Added;
                        dbContext.SaveChanges();

                        return(RedirectToAction("Index"));
                    }
                }

                using (var dbContext = new MvclibraryEntities())
                {
                    var s = dbContext.category.ToList();

                    newBook.CategoryList = s.Select(x => new SelectListItem
                    {
                        Value = x.Id.ToString(),
                        Text  = x.Name
                    });
                }
                return(View(newBook));
            }
            catch
            {
                return(View(newBook));
            }
        }
Esempio n. 6
0
        public IActionResult AddBook(BookAddViewModel model)
        {
            model.Book.UpdateDate = DateTime.Now;
            model.Book.UploadDate = DateTime.Now;
            model.Book.Tags.AddRange(GetTagsToAdd(model.Tags));

            dbContext.Books.Add(model.Book);

            AddChapter(model.Book, 1, null);

            dbContext.SaveChanges();

            return(RedirectToAction("Index", new { userId = model.Book.ApplicationUserId }));
        }
Esempio n. 7
0
        public IActionResult EditTitle(BookAddViewModel model)
        {
            var book = dbContext.Books.Include(book => book.Tags).FirstOrDefault(book => book.Id == model.Book.Id);

            book.Name        = model.Book.Name;
            book.Genre       = model.Book.Genre;
            book.Description = model.Book.Description;

            EditBookTags(book, book.Tags, model.Tags);

            dbContext.SaveChanges();
            bookUdpate.Invoke(model.Book.Id);
            return(RedirectToAction("Index", new { userId = model.Book.ApplicationUserId }));
        }
Esempio n. 8
0
        public void Insert(BookAddViewModel user)
        {
            Book book = new Book();

            book.Name     = user.Name;
            book.AuthorId = user.AuthorId;
            book.BookUrl  = BookUrl == null ? user.BookUrl : BookUrl;
            book.PhotoUrl = PhotoUrl == null ? user.PhotoUrl : PhotoUrl;

            _context.Books.Add(book);
            _context.SaveChanges();
            BookUrl  = null;
            PhotoUrl = null;
        }
Esempio n. 9
0
        // GET: Books/Create
        public ActionResult Create()
        {
            using (var dbContext = new MvclibraryEntities())
            {
                var s   = dbContext.category.ToList();
                var zvm = new BookAddViewModel();

                zvm.CategoryList = s.Select(x => new SelectListItem
                {
                    Value = x.Id.ToString(),
                    Text  = x.Name
                });

                return(View(zvm));
            }
        }
Esempio n. 10
0
        public async Task <IActionResult> Add(BookAddViewModel viewModel)
        {
            if (this.ModelState.IsValid)
            {
                await _context.Books.AddAsync(new Book(0, viewModel.Title));

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View(viewModel));
                //return UnprocessableEntity();
            }
        }
Esempio n. 11
0
        public ActionResult Edit(BookAddViewModel bvm)
        {
            try
            {
                // TODO: Add update logic here
                if (ModelState.IsValid)
                {
                    using (var dbContext = new MvclibraryEntities())
                    {
                        var books = dbContext.Books.ToList();
                        if (books.Where(b => b.ISBN == bvm.ISBN && b.Id != bvm.Id).FirstOrDefault() != null)
                        {
                            ModelState.AddModelError("BookExist", "Książka o podanym ISBN juz istnieje");
                            bvm.CategoryList = dbContext.category.ToList().Select(x => new SelectListItem
                            {
                                Value = x.Id.ToString(),
                                Text  = x.Name
                            });
                            return(View(bvm));
                        }
                        var editBook = dbContext.Books.Where(b => b.Id == bvm.Id).FirstOrDefault();

                        editBook.ISBN                   = bvm.ISBN;
                        editBook.Title                  = bvm.Title;
                        editBook.Author                 = bvm.Author;
                        editBook.CategoryId             = int.Parse(bvm.SelectedCategoryId);
                        dbContext.Entry(editBook).State = EntityState.Modified;
                        dbContext.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
                using (var dbContext = new MvclibraryEntities())
                {
                    bvm.CategoryList = dbContext.category.ToList().Select(x => new SelectListItem
                    {
                        Value = x.Id.ToString(),
                        Text  = x.Name
                    });

                    return(View(bvm));
                }
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 12
0
        public async Task <IActionResult> AddBook(BookAddViewModel model)
        {
            if (ModelState.IsValid)
            {
                await _activityService.AddBookAsync(model.Id, model.Book);

                AlertSuccess = $"Added book '{model.Book.Title}'";
                return(RedirectToAction("Books", new { id = model.Id }));
            }
            else
            {
                var user = await _userService.GetDetails(model.Id);

                SetPageTitle(user, "Add Book");

                return(View(model));
            }
        }
Esempio n. 13
0
        public async Task <IActionResult> AddBook(int id)
        {
            try
            {
                var user = await _userService.GetDetails(id);

                SetPageTitle(user, "Add Book");

                BookAddViewModel viewModel = new BookAddViewModel()
                {
                    Id = id
                };
                return(View(viewModel));
            }
            catch (GraException gex)
            {
                ShowAlertWarning("Unable to add book for participant: ", gex);
                return(RedirectToAction("Index"));
            }
        }
Esempio n. 14
0
        public async Task <IActionResult> Add()
        {
            var viewModel = new BookAddViewModel();

            if (viewModel == null)
            {
                return(NotFound());
            }
            else
            {
                var books = await _context.Books
                            .Select(b => new SelectListItem
                {
                    Text  = b.Title,
                    Value = b.Id.ToString(),
                })
                            .ToListAsync();

                return(View(viewModel));
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Checking books's input and sending it to the database
        /// </summary>
        /// <returns>True if book sent to DB, otherwise false</returns>
        private bool AddItemBook()
        {
            BookAddViewModel viewmodel = (BookAddViewModel)DataContext;
            Book             book      = viewmodel.MyBook;

            if (string.IsNullOrEmpty(book.Title))
            {
                MessageBox.Show("Title cannnot be empty.");
                return(false);
            }

            if (book.Author_AtBook == null)
            {
                MessageBox.Show("Author must be added.");
                return(false);
            }
            if (book.Genre_AtBook == null)
            {
                MessageBox.Show("Genre must be added.");
                return(false);
            }

            try
            {
                int id = MSAConnectionDB.SaveBookToDB(book);
                book.BookId = id;
                Books.AddBook(book);
                Genres.AddBookToGenre(book, book.Genre_AtBook);
                Authors.AddBookToAuthor(book, book.Author_AtBook);
                ActivateMainWindow();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            return(true);
        }
        public async Task <bool> Post(BookAddViewModel model)
        {
            _bookService.Insert(model);

            return(true);
        }
Esempio n. 17
0
 /// <summary>
 /// Showing book's adding view
 /// </summary>
 /// <param name="sender">The source of the event</param>
 /// <param name="e">The instance containing the event data</param>
 private void BookAddView_Selected(object sender, RoutedEventArgs e)
 {
     DataContext = new BookAddViewModel();
 }