public Facture BuyProducts(string email, Guid productId, int productCount) { var curClient = _dataRepository.GetClient(email); if (curClient == null) { throw new ArgumentException($"Client with email '{email}' does not exists!"); } var curOffer = _dataRepository.GetOffer(productId); if (curOffer == null) { throw new ArgumentException($"Offer for this product with id '{productId}' does not exists!"); } if (curOffer.ProductsInStock <= 0) { throw new InvalidOperationException("Currently, there are no products in stock, we are sorry!"); } if (curOffer.ProductsInStock < productCount) { throw new InvalidOperationException("You want to buy more products than we have in stock!"); } curOffer.ProductsInStock -= productCount; _dataRepository.UpdateOffer(productId, curOffer); var facture = new Facture(Guid.NewGuid(), curClient, curOffer, DateTimeOffset.Now, productCount); _dataRepository.AddEvent(facture); return(facture); }
public void AddEvent_Test_Successful() { AddClient_Test_Successful(); AddOffer_Test_Successful(); _dataRepository.AddEvent(_facture); Assert.AreEqual(EventNumber + 1, _dataRepository.GetAllEvents().Count()); Assert.AreSame(_facture, _dataRepository.GetEvent(_facture.Id)); }
public void EventTests() { Customer temp = repository.GetCustomer("O1"); DateTime now = DateTime.Now; Event b = new BuyingEvent("b1", repository.GetState(), temp, now); repository.AddEvent(b); Assert.AreEqual(repository.GetAllEventsNumber(), 1); }
public void RentBook(Reader reader, BookState bookState) { if (bookState.Available) { IDataRepository.AddEvent(new BookRent(reader, bookState, DateTime.Now)); return; } throw new InvalidOperationException("Cannot rent this book"); }
public void LendBook(Customer customer, BookCopy bookCopy) { var lend = new LendBookEvent(bookCopy, customer, _dateProvider.Now()); try { _dataRepository.AddEvent(lend); } catch (EventException e) { throw new DataServiceException(e); } }
public void CannotRemoveReaderWithBorrowedBook() { Reader reader = new Reader("Artur", "Xinski", 123456987); BookEvent rent = new BookRent( reader, new BookState(new Book("111-222-333", "Wojciech Sowa", "Life is life", "Amazing book"), true, DateTime.Now)); dataRepository.AddReader(reader); dataRepository.AddEvent(rent); Assert.ThrowsException <InvalidOperationException>(() => dataRepository.DeleteReader(dataContext.ReadersList.Count - 1)); }
public Invoice BuyBook(Client client, CopyDetails copyDetails, string description) { if (copyDetails.Count <= 0) { throw new InvalidOperationException("We don't have these books, wait for book stock updating."); } Invoice createdInvoice = new Invoice(client, copyDetails, DateTime.Now, description); copyDetails.Count -= 1; _dataRepository.UpdateCopyDetails(copyDetails, this._dataRepository.FindCopyDetails(copyDetails)); _dataRepository.AddEvent(createdInvoice); return(createdInvoice); }
void AddEvent(Client client, Status status, string description, Type type) { Event eventToAdd; if (type == typeof(DestroyEvent)) { eventToAdd = new DestroyEvent(new Guid(), client, status, description); _dataRepository.AddEvent(eventToAdd); } else if (type == typeof(SellEvent)) { eventToAdd = new SellEvent(new Guid(), client, status, description); _dataRepository.AddEvent(eventToAdd); } else if (type == typeof(BuyEvent)) { eventToAdd = new BuyEvent(new Guid(), client, status, description); _dataRepository.AddEvent(eventToAdd); } }
public async Task <IActionResult> Post([FromBody] Event @event) { if (@event == null) { return(BadRequest("Event is null.")); } _eventRepository.AddEvent(@event); return(CreatedAtRoute( "Get", new { Id = @event.Id }, @event)); }
//Event public void AddEvent(Event e) { repository.AddEvent(e); }
public void SellBooks(Client client, BookState bookState, int quantity) { Event sell = new Sale(client, bookState, DateTimeOffset.Now, quantity); dataRepository.AddEvent(sell); }
public void PurchaceBook(Client client, BookExample bookExample) { dataRepository.AddEvent(new Purchase(client, bookExample, DateTime.Now)); }