public void BuildsAListOfNameValueObjectsBasedOnOrigins()
        {
            var viewDataDictionary = new ViewDataDictionary();
            var order = new Order();
            
            var origins = new List<string>
            {
                "Test Origin 1",
                "Test Origin 2"
            };

            Mock.Arrange(() => _mockOriginRepository.GetAllOrigins()).Returns(origins.AsQueryable()).OccursOnce();
            Mock.Arrange(() => _mockDestinationRepository.GetAllDestinations()).Returns(new string[0].AsQueryable());

            var builder = new OrderViewDataBuilder(_mockOriginRepository, _mockDestinationRepository, _mockPackageTypeSelectListBuilder);

            builder.BuildViewData(viewDataDictionary, order);

            Mock.AssertAll(_mockOriginRepository);
            var result = viewDataDictionary["Origins"];
            Assert.IsNotNull(result);
            var resultList = ((IEnumerable<dynamic>) result).ToList();
            Assert.AreEqual(2, resultList.Count());

            Assert.AreEqual("Test Origin 1", resultList[0].Name);
            Assert.AreEqual("Test Origin 1", resultList[0].Value);
            
            Assert.AreEqual("Test Origin 2", resultList[1].Name);
            Assert.AreEqual("Test Origin 2", resultList[1].Value);
        }
 public void BuildViewData(ViewDataDictionary viewDataDictionary, Order order)
 {
     viewDataDictionary.Add("Origins", _originRepository.GetAllOrigins().Select(o => new { Name = o, Value = o }));
     viewDataDictionary.Add("Customer", order.Customer);
     viewDataDictionary.Add("PackageTypes", _packageTypeSelectListBuilder.BuildSelectList());
     viewDataDictionary.Add("Destinations", _destinationRepository.GetAllDestinations().Select(d => new { Name = d, Value = d }));
 }
        public void CopyThePropertiesFromTheOrderIntoTheViewModel()
        {
            Order order = new Order
                {
                    OrderId = 100,
                    OrderNumber = "Test Order",
                    ContractWeight = 100m,
                    ContractAmount = 100m,
                    OrderDate = DateTime.Now,
                    IsActive = true,
                    ContractCurrencyTypeId = 10,
                    CustomerId = 12,
                    PaymentTerm1 = new PaymentTerm(),
                    PaymentTerm2 = new PaymentTerm(),
                    PaymentTermsOverride = "Test override",
                    IntentComments = "Intent comment",
                    InvoiceComments = "Invoice comment",
                    FooterComments = "Footer comment",
                    HeaderComments = "Header comment"
                };

            OrderViewModelConverter converter = new OrderViewModelConverter();

            var result = converter.Convert(order);

            Assert.IsNotNull(result);
            Assert.AreEqual(order.OrderId, result.OrderId);
            Assert.AreEqual(order.OrderNumber, result.OrderNumber);
            Assert.AreEqual(order.ContractAmount, result.ContractAmount);
            Assert.AreEqual(order.ContractWeight, result.ContractWeight);
            Assert.AreEqual(order.OrderDate, result.OrderDate);
            Assert.AreEqual(order.IsActive, result.IsActive);
            Assert.AreEqual(order.ContractCurrencyTypeId, result.CurrencyTypeId);
            Assert.AreEqual(order.CustomerId, result.CustomerId);
            Assert.AreEqual(order.PaymentTermsOverride, result.PaymentTermsOverride);
            Assert.AreEqual(order.PaymentTerm1, result.PaymentTerm1.PaymentTerm);
            Assert.AreEqual(order.PaymentTerm2, result.PaymentTerm2.PaymentTerm);
            Assert.AreEqual(order.IntentComments, result.IntentComments);
            Assert.AreEqual(order.InvoiceComments, result.InvoiceComments);
            Assert.AreEqual(order.FooterComments, result.FooterComments);
            Assert.AreEqual(order.HeaderComments, result.HeaderComments);
        }
        public void SetTheCustomerKeyInTheViewData()
        {
            var viewDataDictionary = new ViewDataDictionary();
            var order = new Order
                {
                    Customer = new Customer
                        {
                            CustomerId = 120
                        }
                };

            Mock.Arrange(() => _mockOriginRepository.GetAllOrigins()).Returns(new string[0].AsQueryable());
            Mock.Arrange(() => _mockDestinationRepository.GetAllDestinations()).Returns(new string[0].AsQueryable());

            var builder = new OrderViewDataBuilder(_mockOriginRepository, _mockDestinationRepository,
                                                   _mockPackageTypeSelectListBuilder);

            builder.BuildViewData(viewDataDictionary, order);

            Customer customer = (Customer) viewDataDictionary["Customer"];
            Assert.AreEqual(order.Customer, customer);
        }
 public void Delete(Order order)
 {
     _salesHubDbContext.Orders.Remove(order);
 }
 public void Add(Order order)
 {
     _salesHubDbContext.Orders.Add(order);
 }
        public void SetPackageTypeKeyInTheViewData()
        {
            var viewDataDictionary = new ViewDataDictionary();
            var order = new Order();
            var packageTypes = new List<SelectListItem>
                {
                    new SelectListItem
                        {
                            Text = "Test Item",
                            Value = "Test Value"
                        }
                };

            Mock.Arrange(() => _mockOriginRepository.GetAllOrigins()).Returns(new string[0].AsQueryable());
            Mock.Arrange(() => _mockDestinationRepository.GetAllDestinations()).Returns(new string[0].AsQueryable());
            Mock.Arrange(() => _mockPackageTypeSelectListBuilder.BuildSelectList()).Returns(packageTypes).OccursOnce();

            var builder = new OrderViewDataBuilder(_mockOriginRepository, _mockDestinationRepository,
                                                   _mockPackageTypeSelectListBuilder);

            builder.BuildViewData(viewDataDictionary, order);

            var result = (IList<SelectListItem>) viewDataDictionary["PackageTypes"];

            Mock.AssertAll(_mockPackageTypeSelectListBuilder);

            Assert.AreEqual(packageTypes, result);
        }
        public void SetDestinationsKeyInTheViewData()
        {
            var viewDataDictionary = new ViewDataDictionary();
            var order = new Order();

            var destinations = new List<string> {"Test Destination"};

            Mock.Arrange(() => _mockOriginRepository.GetAllOrigins()).Returns(new string[0].AsQueryable());
            Mock.Arrange(() => _mockDestinationRepository.GetAllDestinations()).Returns(destinations.AsQueryable()).OccursOnce();
            Mock.Arrange(() => _mockPackageTypeSelectListBuilder.BuildSelectList()).Returns(new List<SelectListItem>());

            var builder = new OrderViewDataBuilder(_mockOriginRepository, _mockDestinationRepository,
                                                   _mockPackageTypeSelectListBuilder);

            builder.BuildViewData(viewDataDictionary, order);

            var result = ((IEnumerable<dynamic>) viewDataDictionary["Destinations"]).ToList();

            Mock.AssertAll(_mockDestinationRepository);

            Assert.AreEqual("Test Destination", result[0].Name);
            Assert.AreEqual("Test Destination", result[0].Value);
        }
        public ActionResult New(int id, OrderViewModel orderViewModel)
        {
            Customer customer = _customerRepository.GetCustomerById(id);

            if (orderViewModel.PaymentTerm1.PaymentTerm.SplitPercentage + orderViewModel.PaymentTerm2.PaymentTerm.SplitPercentage != 1M)
            {
                ModelState.AddModelError("", "Split Percentages Must Total 100%");
            }
            if (!ModelState.IsValid)
            {
                orderViewModel.IsNew = true;
                SetViewModelFields(orderViewModel, id);
                return View(orderViewModel);
            }

            var order = new Order();

            CopyOrderViewModelToOrder(orderViewModel, order);
            order.CustomerId = customer.CustomerId;

            orderViewModel.PaymentTerm1.PaymentTerm.PaymentTermId = order.PaymentTerm1 != null ? order.PaymentTerm1.PaymentTermId : 0;
            orderViewModel.PaymentTerm2.PaymentTerm.PaymentTermId = order.PaymentTerm2 != null ? order.PaymentTerm2.PaymentTermId : 0;
            order.PaymentTerm1 = _paymentTermProcessor.ProcessPaymentTerm(orderViewModel.PaymentTerm1.PaymentTerm);
            order.PaymentTerm2 = _paymentTermProcessor.ProcessPaymentTerm(orderViewModel.PaymentTerm2.PaymentTerm);

            orderViewModel.SavedSuccessfully = true;

            _orderRepository.Add(order);
            _orderRepository.SaveChanges();

            return RedirectToAction("Edit", new {id = order.OrderId});
        }
 private void CopyOrderViewModelToOrder(OrderViewModel orderViewModel, Order order)
 {
     order.OrderId = orderViewModel.OrderId;
     order.OrderNumber = orderViewModel.OrderNumber;
     order.ContractWeight = orderViewModel.ContractWeight;
     order.ContractAmount = orderViewModel.ContractAmount;
     order.OrderDate = orderViewModel.OrderDate;
     order.IsActive = orderViewModel.IsActive;
     order.ContractCurrencyTypeId = order.ContractCurrencyTypeId;
     order.PaymentTermsOverride = orderViewModel.PaymentTermsOverride;
     order.IntentComments = orderViewModel.IntentComments;
     order.InvoiceComments = orderViewModel.InvoiceComments;
     order.FooterComments = orderViewModel.FooterComments;
     order.HeaderComments = orderViewModel.HeaderComments;
 }