public void TransferInvoice() { var buyerA = new Buyer() { Id = 1, Name = "Michel" }; var invoice = new Invoice() { Id = 1, DueDate = DateTime.Now, Value = 10 }; buyerA.AddInvoice(invoice); var buyerB = new Buyer() { Id = 2, Name = "Michel" }; buyerRepositoryMock.GetById(buyerA.Id).Returns(buyerA); buyerRepositoryMock.GetById(buyerB.Id).Returns(buyerB); buyerService.TransferInvoice(buyerA, buyerB, invoice); //Asserts buyerRepositoryMock.Received(2).GetById(Arg.Any <int>()); buyerRepositoryMock.Received().Save(); Assert.IsNotNull(buyerB.Invoices); Assert.AreEqual(1, buyerB.Invoices.Count); }
/// <summary> /// Request new Quotation /// </summary> /// <param name="model"></param> public void RequestQuote(QuotationViewModel model) { Buyer buyer = new Buyer(); if (model.BuyerId != null) { // retrieve existing buyer buyer = _buyerRepository.GetById(model.BuyerId.Value); } else { // create a new buyer and add it to the db buyer = _buyerRepository.Add(new Buyer(model.FullName, model.ContactEmail, model.PhoneNumber) { ShippingAddress = new Address(model.StreetAddress, model.City, model.State, model.Country, model.ZipCode), BillingAddress = new Address(model.StreetAddress, model.City, model.State, model.Country, model.ZipCode) }); } List <OrderItem> orderItems = model.OrderItems .Select(o => new OrderItem { PartNumber = o.PartNumber, Quantity = o.Quantity }).ToList(); _orderService.CreateOrder(buyer.Id, orderItems); }
public void AddBuyer(Buyer buyer) { if (buyer == null) { throw new ArgumentNullException(nameof(buyer)); } var currentBuyer = _buyerRepository.GetById(buyer.Id); if (currentBuyer != null) { throw new Exception("Buyer already exist."); } currentBuyer.Name = "joao"; buyer.AddContact(new Contact() { Description = "michel" }); _buyerRepository.Add(buyer); _unityOfWork.Commit(); }
public void TransferInvoice(Buyer from, Buyer to, Invoice invoice) { if (@from == null) { throw new ArgumentNullException(nameof(@from)); } if (to == null) { throw new ArgumentNullException(nameof(to)); } if (invoice == null) { throw new ArgumentNullException(nameof(invoice)); } _logger.Info("Getting buyer by Id "); var buyerA = _repository.GetById(from.Id); if (buyerA is null) { throw new Exception("Buyer not found"); } var buyerB = _repository.GetById(to.Id); if (buyerB is null) { throw new Exception("Buyer not found"); } var fromInvoice = buyerA.Invoices.SingleOrDefault(i => i.Id == invoice.Id); if (fromInvoice is null) { throw new Exception("Invoice not found"); } buyerA.RemoveInvoice(fromInvoice); buyerB.AddInvoice(fromInvoice); _repository.Save(); }
public IActionResult GetById(string Bid) { try { return(Ok(_repo.GetById(Bid))); } catch (Exception e) { return(NotFound(e.InnerException.Message)); } }
private async Task InsertBuyerIfNecessary(Expense expense) { var buyer = await _buyerRepository.GetById(expense.BuyerId); if (buyer != null) { expense.SetBuyer(buyer); return; } await _buyerRepository.Insert(expense.Buyer); }
Buyer IBuyerBusinessService.GetById(int buyerId) { return(repository.GetById(buyerId)); }