Example #1
0
        public void Should_Edit_Book_With_Quantities_In_Offices()
        {
            MockEditBook();
            var bookDto = new EditBookDTO
            {
                OrganizationId   = 2,
                Author           = "test1",
                Id               = 1,
                QuantityByOffice = new List <NewBookQuantityDTO>
                {
                    new NewBookQuantityDTO
                    {
                        BookQuantity = 0,
                        OfficeId     = 1
                    },
                    new NewBookQuantityDTO
                    {
                        BookQuantity = 50,
                        OfficeId     = 2
                    }
                }
            };

            _bookService.EditBook(bookDto);
            var bookOffices = _booksDbSet.First().BookOffices;

            Assert.AreEqual(0, bookOffices.First(x => x.OfficeId == 1).Quantity);
            Assert.AreEqual(50, bookOffices.First(x => x.OfficeId == 2).Quantity);
            Assert.AreEqual("test1", _booksDbSet.First().Author);
        }
Example #2
0
        public void UpdateBook(EditBookDTO newData)
        {
            Book book = FindBook(newData.Id);

            book.Id = newData.Id;

            if (newData.Title != null && newData.Title != book.Title)
            {
                book.Title = newData.Title;
            }
            if (newData.Genre != null && newData.Genre != book.Genre)
            {
                book.Genre = newData.Genre;
            }
            if (newData.Year != null && newData.Year != book.Year)
            {
                book.Year = newData.Year;
            }
            if (newData.Pages != null && newData.Pages != book.Pages)
            {
                book.Pages = newData.Pages;
            }

            db.SaveChanges();
        }
Example #3
0
        public IActionResult Edit(EditBookDTO newData)
        {
            Book newBook = bookServices.FindBook(newData.Title);
            Book oldBook = bookServices.FindBook(newData.Id);

            if (newBook != null && oldBook.Title != newBook.Title)
            {
                ViewData.Add("TitleRepeatingError", "A book with this title already exists!");
                return(View(newData));
            }

            try
            {
                bookServices.UpdateBook(newData);
            }
            catch (ArgumentException ae)
            {
                ViewData.Add("ShortTitle", ae.Message);
                return(View(newData));
            }

            bookServices.UpdateBook(newData);

            return(RedirectToAction(nameof(Books)));
        }
Example #4
0
        public ActionResult Edit(Guid id, EditBookDTO dto)
        {
            var commandId = ApiRequest.Put <Guid>($"{_inventoryApiBaseUrl}/api/Books/{dto.BookId}", dto);

            if (commandId != Guid.Empty)
            {
                return(RedirectToAction("List"));
            }
            else
            {
                return(View(dto));
            }
        }
Example #5
0
		public ActionResult Edit(Guid id, EditBookDTO dto)
		{
			var commandId = ApiRequest.Put<Guid>($"{_apiGatewayUrl}/api/books/{dto.BookId}", dto);

			if (commandId != Guid.Empty)
			{
				return RedirectToAction("List");
			}
			else
			{
				return View(dto);
			}
		}
Example #6
0
 private void ManageQuantitiesInOffices(EditBookDTO editedBook, Book existingBook)
 {
     foreach (var officeQuantity in editedBook.QuantityByOffice)
     {
         var bookOfficeExists = existingBook.BookOffices.Any(x => x.OfficeId == officeQuantity.OfficeId);
         if (!bookOfficeExists)
         {
             existingBook.BookOffices.Add(MapBookDtoToBookOfficeEntity(existingBook, officeQuantity, editedBook.UserId));
         }
         else
         {
             var office = existingBook.BookOffices.First(x => x.OfficeId == officeQuantity.OfficeId);
             office.Quantity = officeQuantity.BookQuantity;
         }
     }
 }
        public void IsChangingYearCorrectly()
        {
            Book        book        = db.Books.FirstOrDefault();
            EditBookDTO editBookDTO = new EditBookDTO
            {
                Id    = book.Id,
                Title = book.Title,
                Genre = book.Genre,
                Pages = book.Pages,
                Year  = 2021
            };

            bookServices.UpdateBook(editBookDTO);

            Assert.AreEqual(2021, book.Year);
        }
        public void NotChangingYearWhenNewValueIsEqualToOldValue()
        {
            Book        book        = db.Books.FirstOrDefault();
            EditBookDTO editBookDTO = new EditBookDTO
            {
                Id    = book.Id,
                Title = book.Title,
                Genre = book.Genre,
                Pages = book.Pages,
                Year  = 2021
            };

            bookServices.UpdateBook(editBookDTO);

            Assert.AreEqual(100, book.Pages);
        }
        public void NotChangingTitleWhenNewValueIsNull()
        {
            Book        book        = db.Books.FirstOrDefault();
            EditBookDTO editBookDTO = new EditBookDTO
            {
                Id    = book.Id,
                Title = null,
                Genre = book.Genre,
                Pages = book.Pages,
                Year  = book.Year
            };

            bookServices.UpdateBook(editBookDTO);

            Assert.AreEqual("title1", book.Title);
        }
Example #10
0
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction(nameof(Books)));
            }

            Book book = bookServices.FindBook(id);

            EditBookDTO result = new EditBookDTO
            {
                Id    = book.Id,
                Title = book.Title,
                Genre = book.Genre,
                Year  = book.Year,
                Pages = book.Pages
            };

            return(View(result));
        }
Example #11
0
        public ActionResult Edit(Guid id, EditBookDTO dto)
        {
            var data = new NameValueCollection();

            data.Add("BookId", dto.BookId.ToString());
            data.Add("BookName", dto.BookName);
            data.Add("ISBN", dto.ISBN);
            data.Add("IssueDate", dto.DateIssued.ToString("yyyy-MM-dd"));
            data.Add("Description", dto.Description);

            var commandId = ApiRequestWithFormUrlEncodedContent.Put <Guid>($"{_inventoryApiBaseUrl}/api/Books/{dto.BookId}", data);

            if (commandId != Guid.Empty)
            {
                return(RedirectToAction("List"));
            }
            else
            {
                return(View(dto));
            }
        }
Example #12
0
        public void EditBook(EditBookDTO editedBook)
        {
            var existingBook = _booksDbSet
                               .Include(book => book.BookOffices)
                               .First(book =>
                                      book.Id == editedBook.Id &&
                                      book.OrganizationId == editedBook.OrganizationId);

            existingBook.Modified          = DateTime.UtcNow;
            existingBook.ModifiedBy        = editedBook.UserId;
            existingBook.Title             = editedBook.Title;
            existingBook.Author            = editedBook.Author;
            existingBook.Code              = editedBook.Isbn;
            existingBook.Url               = editedBook.Url;
            existingBook.ApplicationUserId = editedBook.OwnerId;
            existingBook.Note              = editedBook.Note;

            ValidateQuantitiesValues(editedBook.QuantityByOffice.Select(o => o.BookQuantity));
            ManageQuantitiesInOffices(editedBook, existingBook);
            _uow.SaveChanges(false);
        }