public void TestAddBookAlreadyExist()
        {
            _initializer.EnsureServerRestart();
            _page.Navigate();

            var beforeAdd = _page.ExtractBooksTable();
            var toAdd     = new AddBookModel()
            {
                AddName = "testName", AddCount = 2
            };

            _page.PopulateNewBook(toAdd);
            _page.ClickBookAddButton();
            var afterFirstAdd = _page.ExtractBooksTable();

            _page.PopulateNewBook(toAdd);
            _page.ClickBookAddButton();
            var afterSecondAdd = _page.ExtractBooksTable();


            Assert.Equal(beforeAdd.Count + 1, afterFirstAdd.Count);
            Assert.Equal(afterFirstAdd.Count, afterSecondAdd.Count);

            // книги должны суммироваться
            Assert.Contains(afterSecondAdd, a => a.count == toAdd.AddCount * 2 && a.name == toAdd.AddName);
        }
Exemple #2
0
        public ActionResult TryAddBook(AddBookModel model)
        {
            if (model == null)
            {
                return(RedirectToAction("AddBook", "Books"));
            }
            if (CurrentUser == null || !CurrentUser.IsAdmin)
            {
                return(RedirectToAction("Index", "Books"));
            }

            DataContext.Books.InsertOnSubmit(new Book()
            {
                Title   = model.Title,
                Author  = model.Author,
                Genre   = model.Genre,
                Amount  = model.Amount,
                Pages   = model.Pages,
                Price   = model.Price,
                Year    = model.Year,
                PhotoId = model?.PhotoId
            });
            DataContext.SubmitChanges();

            return(RedirectToAction("Index", "Books"));
        }
Exemple #3
0
        public async Task <IActionResult> Post([FromBody] AddBookModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                var book = new Book
                {
                    Name            = model.Name,
                    AuthorName      = model.AuthorName,
                    Edition         = model.Edition,
                    PublicationDate = model.PublicationDate,
                    ISDN            = model.ISDN,
                    Category        = _repository.GetCategoryWithBooks(model.CategoryId)
                };

                _repository.Add(book);
                if (await _repository.SaveAllAsync())
                {
                    var newUri = Url.Link("BookGet", new { id = book.Id });
                    return(Created(newUri, book));
                }
            }
            catch (Exception ex)
            { Console.Write(ex.Message); }
            return(BadRequest("Could not post Book"));
        }
        public void TestGiveBookWrongBookName()
        {
            _initializer.EnsureServerRestart();
            _page.Navigate();

            // добавляем книгу
            var newBook = new AddBookModel()
            {
                AddName = "testName", AddCount = 2
            };

            _page.PopulateNewBook(newBook);
            _page.ClickBookAddButton();

            // добавляем клиента
            var newClientName = "testClientName";

            _page.PopulateNewClientName(newClientName);
            _page.ClickNewClientAddButton();

            // даём клиенту несуществующую книгу
            var info = new GiveBookModel()
            {
                GiveBookName = "asdasdasd", GiveToClientId = 1
            };

            _page.PopulateGiveBookInfo(info);
            _page.ClickGiveBookButton();

            // должна быть ошибка
            Assert.Contains("Данной книги не существует", _page.ErrorTextString);
        }
        private void UpdateListBook(AddBookModel context)
        {
            App.Current.Dispatcher.Invoke((Action) delegate
            {
                context.ListBook.Clear();
            });
            SQLiteConnection con;

            SqlMethods.SqlConnect(out con);
            var updateCommand = con.CreateCommand();

            updateCommand.CommandText = "SELECT Number FROM Books ORDER BY BookId DESC";
            SQLiteDataReader r = updateCommand.ExecuteReader();
            int i = 20;

            while (r.Read() && i-- > 0)
            {
                int result;
                int.TryParse(Convert.ToString(r["Number"]), out result);
                App.Current.Dispatcher.Invoke((Action) delegate
                {
                    context.ListBook.Add(result);
                });
            }
            r.Close();
            con.Close();
        }
Exemple #6
0
 public ActionResult SaveBook(AddBookModel addBookModel)
 {
     if (ModelState.IsValid)
     {
         try
         {
             DataTable dt = libraryService.AddBook(addBookModel);
             if (dt.Rows[0][0].ToString() == "Y")
             {
                 TempData["Status"] = "Y";
                 return(RedirectToAction("AddBook"));
             }
             else
             {
                 TempData["Status"] = "N";
                 return(View("AddBook"));
             }
         }
         catch (Exception ex)
         {
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             ModelState.AddModelError("", ex.Message);
             TempData["Fail"] = "Fail";
             return(View("AddBook"));
         }
     }
     else
     {
         TempData["ModelsError"] = "Error";
         return(RedirectToAction("AddBook"));
     }
 }//.End SaveBook
        private void AddBook_Closing(object sender, CancelEventArgs e)
        {
            bool         containData = false;
            AddBookModel context     = this.DataContext as AddBookModel;

            containData = context.Number != 0 ||
                          context.Signature1 != NotAvalable ||
                          !string.IsNullOrWhiteSpace(context.Signature2) ||
                          !string.IsNullOrWhiteSpace(context.Signature3) ||
                          context.Author1 != NotAvalable ||
                          !string.IsNullOrWhiteSpace(context.Author2) ||
                          !string.IsNullOrWhiteSpace(context.Author3) ||
                          !string.IsNullOrWhiteSpace(context.Title) ||
                          context.Publisher != NotAvalable ||
                          context.Version != 0 ||
                          context.Year != 0 ||
                          context.Medium != NotAvalable ||
                          context.Place != NotAvalable ||
                          context.Date != "01/01/1970" ||
                          context.Pages != 0 ||
                          context.Price != 0;

            if (containData)
            {
                string           message = Application.Current.FindResource("AddBook.CodeBehind.WarningCancel.Message").ToString();
                string           caption = Application.Current.FindResource("AddBook.CodeBehind.WarningCancel.Caption").ToString();
                MessageBoxResult result  = CustomMessageBox.ShowYesNo(message, caption, CustomMessageBoxButton.Yes, CustomMessageBoxButton.No, MessageBoxImage.Warning);
                //MessageBoxResult result = MessageBox.Show(message, caption, MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (result == MessageBoxResult.No)
                {
                    e.Cancel = true;
                }
            }
        }
Exemple #8
0
        public void PopulateNewBook(AddBookModel model)
        {
            BookAddNameInputElement.SendKeys(model.AddName);

            BookAddCountInputElement.Clear();
            BookAddCountInputElement.SendKeys(model.AddCount.ToString());
        }
        public void TestGiveBookSuccess()
        {
            _initializer.EnsureServerRestart();
            _page.Navigate();

            // добавляем книгу
            var newBook = new AddBookModel()
            {
                AddName = "testName", AddCount = 2
            };

            _page.PopulateNewBook(newBook);
            _page.ClickBookAddButton();

            // добавляем клиента
            var newClientName = "testClientName";

            _page.PopulateNewClientName(newClientName);
            _page.ClickNewClientAddButton();

            var info = new GiveBookModel()
            {
                GiveBookName = newBook.AddName, GiveToClientId = 1
            };

            _page.PopulateGiveBookInfo(info);
            _page.ClickGiveBookButton();

            var afterAdd = _page.ExtractClientTable();

            Assert.Single(afterAdd);
            Assert.Contains(afterAdd, a => a.id == 1 && a.clientName == newClientName && a.bookList.Contains(newBook.AddName));
        }
Exemple #10
0
        public async Task <IActionResult> AddBook(AddBookModel vm)
        {
            var command = new AddBookCommand(vm.AuthorId, vm.Title);
            var result  = await _mediator.Send(command);

            return(result.Match <IActionResult>(data => RedirectToAction("Book", new { bookId = data }),
                                                errors => RedirectToAction("AddBook", new { message = "There were errors" })));
        }
        public ActionResult Update(int id)
        {
            AddBookModel   model = new AddBookModel();
            BookRepository br    = new BookRepository();

            model.book    = br.GetBook(id);
            ViewBag.Title = "Update Book #" + id;
            return(View("Add", model));
        }
        /// <summary>
        /// Adds the books.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public async Task <int> AddBooks(AddBookModel model)
        {
            var book = new Book();

            book = mapper.Map <AddBookModel, Book>(model);
            await context.Books.AddAsync(book);

            return(await context.SaveChangesAsync());
        }
Exemple #13
0
        public IActionResult AddBook(AddBookModel book)
        {
            if (ModelState.IsValid)
            {
                DataStore.Books.AddBook(book);

                return(RedirectToAction("Index", "Home"));
            }
            return(View());
        }
        public ActionResult Add()
        {
            AddBookModel model = new AddBookModel()
            {
                book = new Book()
            };

            ViewBag.Title = "Add new Book to the Store!";

            return(View(model));
        }
Exemple #15
0
        public Task Update(AddBookModel addBookModel)
        {
            var updateresult = this.context.AddBookDB.Where(option => option.BookId == addBookModel.BookId).SingleOrDefault();

            if (updateresult != null)
            {
                updateresult.BookPrice = addBookModel.BookPrice;
                this.context.AddBookDB.Update(updateresult);
                return(Task.Run(() => context.SaveChanges()));
            }
            return(default);
Exemple #16
0
        public async Task <IActionResult> AddBook([FromBody] AddBookModel model)
        {
            var result = await this.manager.AddBooks(model);

            if (result > 0)
            {
                return(this.Ok(new { Succeeded = true }));
            }

            return(this.BadRequest(new { Succeeded = false }));
        }
Exemple #17
0
        public async Task <IActionResult> UpdateBook([FromBody] AddBookModel book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            foreach (var author in book.Authors)
            {
                if (!appDbContext.Authors.Any(x => x.Author == author.Author))
                {
                    await appDbContext.Authors.AddAsync(new Authors { Author = author.Author });
                }
            }

            var BookToUpdate = await appDbContext.Books
                               .Include(x => x.BookCategory)
                               .Include(x => x.BookAuthors)
                               .SingleOrDefaultAsync(s => s.ISBN == book.ISBN);

            bool isCaregoryExist = appDbContext.BookCategories.Any(x => x.CategoryName == book.CategoryName);

            if (!isCaregoryExist)
            {
                await appDbContext.BookCategories.AddAsync(new BookCategory { CategoryName = book.CategoryName });
            }

            // remove authors first
            BookToUpdate.BookAuthors = null;
            await appDbContext.SaveChangesAsync();

            foreach (var author in book.Authors)
            {
                await appDbContext.BookAuthors.AddAsync(new BookAuthor { ISBN = book.ISBN, AuthorId = author.AuthorId });
            }

            await appDbContext.SaveChangesAsync();

            if (BookToUpdate != null)
            {
                BookToUpdate.Title         = book.Title;
                BookToUpdate.Ratings       = book.Ratings;
                BookToUpdate.Pages         = book.Pages;
                BookToUpdate.Quantity      = book.Quantity;
                BookToUpdate.YearOfPublish = book.YearOfPublish;
                BookToUpdate.CategoryId    = book.CategoryId;
            }

            await appDbContext.SaveChangesAsync();


            return(new OkObjectResult("{}"));
        }
Exemple #18
0
        public IActionResult AddBook(int authorId, string message = null)
        {
            if (!string.IsNullOrWhiteSpace(message))
            {
                ViewBag.Message = message;
            }

            var addBookModel = new AddBookModel()
            {
                AuthorId = authorId
            };

            return(View(addBookModel));
        }
        private void BtnSelectSignature_Click(object sender, RoutedEventArgs e)
        {
            AddBookModel context = this.DataContext as AddBookModel;

            //context.Signature1 = string.Empty;
            //context.Signature2 = string.Empty;
            //context.Signature3 = string.Empty;
            new ChooseSignatures(context)
            {
                Owner = this,
                Left  = this.Left + 10,
                Top   = this.Top + 150
            }.ShowDialog();
        }
        public void TestRemoveBusyBook()
        {
            _initializer.EnsureServerRestart();
            _page.Navigate();

            var newBook = new AddBookModel()
            {
                AddName = "testName", AddCount = 2
            };

            _page.PopulateNewBook(newBook);
            _page.ClickBookAddButton();

            var newClientName = "testClientName";

            _page.PopulateNewClientName(newClientName);
            _page.ClickNewClientAddButton();


            var info = new GiveBookModel()
            {
                GiveBookName = newBook.AddName, GiveToClientId = 1
            };

            _page.PopulateGiveBookInfo(info);
            _page.ClickGiveBookButton();

            var removeBook = new RemoveBookModel()
            {
                rmvName = newBook.AddName, rmvCount = 2
            };

            _page.PopulateRemoveBook(removeBook);
            _page.ClickRemoveBook();



            var returnBook = new ReturnBookModel()
            {
                ReturnBookName     = newBook.AddName,
                ReturnFromClientId = 1
            };

            _page.PopulateNewBook(newBook);
            _page.ClickReturnBookButton();

            var afterAdd = _page.ExtractBooksTable();

            Assert.Equal(1, afterAdd.Count);
        }
Exemple #21
0
        public IActionResult AddBook(AddBookModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _dataContainer.Kit.addBook(model.AddName, model.AddCount);
                }
            }
            catch (Exception e)
            {
                TempData["Error"] = e.Message;
            }

            return(RedirectToAction("Index"));
        }
 private int NumberOfSignature(AddBookModel context)
 {
     if (!string.IsNullOrWhiteSpace(context.Signature3) && !string.IsNullOrWhiteSpace(context.Signature2))
     {
         return(3);
     }
     else if (!string.IsNullOrWhiteSpace(context.Signature2))
     {
         return(2);
     }
     else if (string.IsNullOrWhiteSpace(context.Signature3) && string.IsNullOrWhiteSpace(context.Signature2))
     {
         return(1);
     }
     return(0);
 }
 private int NumberOfAuthor(AddBookModel context)
 {
     if (!string.IsNullOrWhiteSpace(context.Author3) && !string.IsNullOrWhiteSpace(context.Author2))
     {
         return(3);
     }
     else if (!string.IsNullOrWhiteSpace(context.Author2))
     {
         return(2);
     }
     else if (string.IsNullOrWhiteSpace(context.Author3) && string.IsNullOrWhiteSpace(context.Author2))
     {
         return(1);
     }
     return(0);
 }
        public ChooseSignatures(AddBookModel preContext)
        {
            this.preContext = preContext;
            ChooseSignaturesModel context = new ChooseSignaturesModel();

            context.Signatures    = new ObservableCollection <Signature>();
            context.SubSignatures = new ObservableCollection <Signature>();
            this.DataContext      = context;
            ReadSignature();
            context.Title = Application.Current.FindResource("ChooseSignature.Title").ToString();
            InitializeComponent();
            EditSig.Visibility    = Visibility.Collapsed;
            EditSubSig.Visibility = Visibility.Collapsed;
            context.IsEdit        = IsEdit;
            context.IdColVisible  = false;
        }
Exemple #25
0
 public ActionResult AddBook(AddBookModel model)
 {
     dbBook = new Book()
     {
         Name        = model.Name,
         Author      = model.Author,
         Cost        = model.Cost,
         PageCount   = model.PageCount,
         Description = model.Description,
         Genre       = model.Genre,
         Type        = model.Type,
         UserId      = _userService.IdTransfer(HttpContext.ApplicationInstance.User.Identity.GetUserId()),
         Id          = Guid.NewGuid()
     };
     _bookService.AddBook(dbBook);
     return(RedirectToAction("Index", "Home"));
 }
Exemple #26
0
        public RequestResult <BookModel> AddBook(AddBookModel model)
        {
            var result = new RequestResult <BookModel>();

            var book = _repositiry.Add(Mapper.Map <AddBookModel, Book>(model));

            if (book != null)
            {
                result.Result  = Mapper.Map <Book, BookModel>(book);
                result.Success = true;
            }
            else
            {
                result.Message = "Error while trying to add the book";
            }

            return(result);
        }
Exemple #27
0
        public async Task <string> AddBook(AddBookModel addBookModel)
        {
            AddBookModel addbook = new AddBookModel()
            {
                BookId          = addBookModel.BookId,
                BookTitle       = addBookModel.BookTitle,
                BookDescription = addBookModel.BookDescription,
                BookPrice       = addBookModel.BookPrice,
                BookImage       = addBookModel.BookImage,
                Author          = addBookModel.Author,
                BooksCount      = addBookModel.BooksCount,
            };
            var add       = this.context.AddBookDB.AddAsync(addbook);
            var addreturn = context.SaveChangesAsync();
            await Task.Run(() => addreturn);

            return("New book added to store");
        }
        public void TestGiveBookNotAvailableBook()
        {
            _initializer.EnsureServerRestart();
            _page.Navigate();

            // добавляем книгу с количеством 0
            var newBook = new AddBookModel()
            {
                AddName = "testName", AddCount = 2
            };

            _page.PopulateNewBook(newBook);
            _page.ClickBookAddButton();

            // добавляем клиента
            var newClientName = "testClientName";

            _page.PopulateNewClientName(newClientName);
            _page.ClickNewClientAddButton();

            // даём клиенту эту книгу
            var info = new GiveBookModel()
            {
                GiveBookName = newBook.AddName, GiveToClientId = 1
            };

            _page.PopulateGiveBookInfo(info);
            _page.ClickGiveBookButton();
            info = new GiveBookModel()
            {
                GiveBookName = newBook.AddName, GiveToClientId = 1
            };
            _page.PopulateGiveBookInfo(info);
            _page.ClickGiveBookButton();
            info = new GiveBookModel()
            {
                GiveBookName = newBook.AddName, GiveToClientId = 1
            };
            _page.PopulateGiveBookInfo(info);
            _page.ClickGiveBookButton();

            // должна быть ошибка
            Assert.Contains("Данной книги нет в наличии", _page.ErrorTextString);
        }
Exemple #29
0
        public ActionResult TryEditBook(AddBookModel model)
        {
            if (model != null)
            {
                Book book = DataContext.Books.FirstOrDefault(bk => bk.Id == model.Id);
                book.Title   = model.Title;
                book.Author  = model.Author;
                book.Genre   = model.Genre;
                book.Pages   = model.Pages;
                book.Year    = model.Year;
                book.Price   = model.Price;
                book.Amount  = model.Amount;
                book.PhotoId = model?.PhotoId;
                DataContext.SubmitChanges();

                return(RedirectToAction("Index", "Books"));
            }
            return(RedirectToAction("EditBook", "Books"));
        }
Exemple #30
0
        public ActionResult AddNewBook(AddBookModel addBookModel, HttpPostedFileBase file)
        {
            Book book = new Book()
            {
                Name              = addBookModel.Name,
                Price             = addBookModel.Price,
                AvailableQuantity = addBookModel.Quantity,
                Picture           = null,
                Description       = addBookModel.Description,
                AddDate           = DateTime.Today.Date
            };

            if (((IBookRepository) new RepositoryFactory().Create <Book>()).InsertWithAuthorPublicationCategory(book, addBookModel.AuthorId, addBookModel.PublicationId, addBookModel.CategoryId))
            {
                TempData["msg"] = "Success";
            }
            TempData["msg"] = "Not successed";
            return(View("Books/AddNewBook"));
        }