Exemplo n.º 1
0
 public static IEnumerable<ChangeItem> GetChangeItems(OrderDTO dto, Order order)
 {
     IEnumerable<ChangeItem> changeItems = from c in dto.Changes
                                           select
                                               new ChangeItem(c.ChangeType,
                                                              DtoToDetail((OrderDetailDTO) c.Object, order));
     return changeItems;
 }
Exemplo n.º 2
0
 public static Order DtoToOrder(OrderDTO dto)
 {
     Order order = new Order()
                       {
                           OrderId = dto.Id,
                           OrderStatus = dto.OrderStatus,
                           OrderDate = dto.OrderDate,
                           ShippedDate = dto.ShippedDate,
                           Customer = new Customer() {CustomerId = dto.CustomerId},
                           Version = dto.Version
                       };
     ValidationHelper.Validate(order);
     return order;
 }
Exemplo n.º 3
0
        public static OrderDTO OrderToDto(Order o)
        {
            OrderDTO dto = new OrderDTO()
                               {
                                   Id = o.OrderId,
                                   CustomerName = o.Customer.ToString(),
                                   CustomerId = o.Customer.CustomerId,
                                   OrderStatus = o.OrderStatus,
                                   OrderDate = o.OrderDate,
                                   ShippedDate = o.ShippedDate,
                                   Version = o.Version,
                                   Details = OrderDetailsToDtos(o)
                               };

            return dto;
        }
        public void TestOrderDetailModel()
        {
            OrderDetailDTO detailDto = new OrderDetailDTO() {Id = 1, QuantityInUnits = 123, UnitPrice = 213, ProductId = 1, ProductName = "FAkeProduct", Version = 1};
            OrderDTO dto = new OrderDTO() {Id = 1, OrderStatus = OrderStatus.Ordered, OrderDate = DateTime.Now, ShippedDate = null, CustomerId = 123, CustomerName = "Fakecustomer"};
            dto.Details.Add(detailDto);

            OrderDetailViewModel orderDetailViewModel = new OrderDetailViewModel(dto, false);
            orderDetailViewModel.Service = serviceFacade;

            Expect.Once.On(serviceFacade).Method("StoreOrder").With(dto);
            orderDetailViewModel.SaveCommand.Command.Execute(null);

            Assert.AreEqual(dto, orderDetailViewModel.Model);
            Assert.AreEqual(Strings.OrderDetailViewModel_DisplayName, orderDetailViewModel.DisplayName);

            OrderItemViewModel detailListViewModel = (OrderItemViewModel) orderDetailViewModel.ListViewModel;
            Assert.AreEqual(detailDto, detailListViewModel.Items.FirstOrDefault());
        }
 public void TestStoreOrder()
 {
     OrderDTO order = new OrderDTO();
     order.Id = 123;
     StoreOrderResponse response = new StoreOrderResponse();
     response.Id = order.Id;
     Expect.Once.On(service).Method("StoreOrder").Will(Return.Value(response));
     serviceFacade.StoreOrder(order);
 }
Exemplo n.º 6
0
        private void RefreshOrderDetailViewModel(OrderViewModel vm, OrderDTO item)
        {
            var vmOrderDetail = GetViewModelFromTempData<OrderDetailViewModel>(typeof(OrderDetailController).FullName);

            if (vmOrderDetail != null && vmOrderDetail.LatestControllerAction != ControllerAction.None)
            {
                vm.OrderDetails = vmOrderDetail;
            }
            else
            {
                vm.OrderDetails = new OrderDetailViewModel(item.Details.ToList());
            }

            vm.OrderDetails.IsReadOnly = CurrentActionName == "Details";
            vm.OrderDetails.ReturnController = CurrentControllerName;
            vm.OrderDetails.ReturnAction = CurrentActionName;
            vm.OrderDetails.ReturnId = CurrentParameterId;
        }
Exemplo n.º 7
0
        protected ActionResult DisplayDetails(OrderDTO item)
        {
            var vm = GetViewModelFromTempData<OrderViewModel>() ?? new OrderViewModel(item, null, false);
            vm.DisplayName = Strings.OrderViewModel_DisplayName;
            vm.Model = item;
            vm.IsNew = item.Id <= 0;
            vm.Customers = vm.Customers ?? Service.GetAllCustomers().ToList();
            vm.OrderStates = Enum.GetNames(typeof(OrderStatus)).ToList();

            // Refreshes the OrderDetailViewModel in OrderViewModel
            RefreshOrderDetailViewModel(vm, item);

            // Marks child entity changes in OrderViewModel
            MarkOrderDetailChanges(vm);

            // Finish Action
            StoreViewModelToTempData(vm);
            StoreViewModelToTempData(vm.OrderDetails, typeof(OrderDetailController).FullName);
            return View(vm);
        }
Exemplo n.º 8
0
        public void TestDtoToDetail()
        {
            OrderDTO orderDTO = new OrderDTO();
            orderDTO.MarkChildForInsertion(new OrderDetailDTO { Id = 1, ProductId = 123, ProductName = "FakeProduct", QuantityInUnits = 123, UnitPrice = 123.32m, Version = 0 });
            orderDTO.MarkChildForUpdate(new OrderDetailDTO { Id = 2, ProductId = 123, ProductName = "FakeProduct", QuantityInUnits = 123, UnitPrice = 123.32m, Version = 0 });
            orderDTO.MarkChildForDeletion(new OrderDetailDTO { Id = 3, ProductId = 123, ProductName = "FakeProduct", QuantityInUnits = 123, UnitPrice = 123.32m, Version = 0 });

            IEnumerable<ChangeItem> changeItems = OrderAdapter.GetChangeItems(orderDTO, new Order());
            Assert.AreEqual<int>(3, changeItems.Count());
        }
Exemplo n.º 9
0
        public void TestDtoToOrder()
        {
            OrderDetailDTO detailDto = new OrderDetailDTO() { Id = 1, QuantityInUnits = 123, UnitPrice = 213, ProductId = 1, ProductName = "FAkeProduct", Version = 1 };
            OrderDTO dto = new OrderDTO() { Id = 1, OrderStatus = OrderStatus.Ordered, OrderDate = DateTime.Now, ShippedDate = null, CustomerId = 123, CustomerName = "Fakecustomer" };
            dto.Details.Add(detailDto);
            Assert.AreEqual(true, dto.IsValid);
            Assert.AreEqual(true, detailDto.IsValid);

            Order order = OrderAdapter.DtoToOrder(dto);
            Assert.AreEqual<int>(dto.Id, order.OrderId);
            Assert.AreEqual<int>((int) dto.OrderStatus, (int) order.OrderStatus);
            Assert.AreEqual<DateTime?>(dto.OrderDate, order.OrderDate);
            Assert.AreEqual<DateTime?>(dto.ShippedDate, order.ShippedDate);
            Assert.AreEqual<int>(dto.CustomerId, order.Customer.CustomerId);
            //TODO: Assert.AreEqual<string>(dto.CustomerName, order.Customer.Username);
            Assert.AreEqual(dto.Version, order.Version);

            //TODO: Assert.AreEqual<int>(dto.Details.Count(), order.Details.Count());
            Assert.AreEqual(true, order.IsValid);
        }
Exemplo n.º 10
0
 public void StoreOrder(OrderDTO order)
 {
     try
     {
         StoreOrderRequest request = new StoreOrderRequest();
         request.Order = order;
         StoreOrderResponse response = Service.StoreOrder(request);
         order.Id = response.Id;
     }
     catch (Exception ex)
     {
         if (ExceptionPolicy.HandleException(ex, "PL Policy")) throw;
     }
 }