Ejemplo n.º 1
0
        private void buttonSave_Click(object sender, RoutedEventArgs e)
        {
            string clientFullName = comboBoxClient.SelectedItem.ToString();

            int clientId = (from c in _clients
                            where c.FullName.Equals(clientFullName)
                            select c.Id)
                           .FirstOrDefault();

            string statusTitle = comboBoxStatus.SelectedItem.ToString();

            int statusId = (from c in _statuses
                            where c.Title.Equals(statusTitle)
                            select c.Id)
                           .FirstOrDefault();

            NewOrderInfoModel newOrderInfoModel = new NewOrderInfoModel()
            {
                ClientId        = clientId,
                OrderDate       = datePicker.Text,
                StatusesId      = statusId,
                OrderReview     = string.Empty,
                TotalPrice      = totalPrice,
                ProductsInOrder = _productInOrderModels
            };

            foreach (FeedbackModel f in _feedbackModels)
            {
                f.ClientId = clientId;
                f.Date     = datePicker.Text;
            }
            _controller.AddOrder(newOrderInfoModel);

            NavigationService.Navigate(new ListOfOrdersWindow());
        }
Ejemplo n.º 2
0
        public void UpdateOrder_WhenValidTestPassed_ShouldUpdateOrder(NewOrderInfoModel newOrderInfo, List <FeedbackModel> feedbackModels,
                                                                      List <FeedbackDTO> feedbackDtos, OrderDTO expectedOrder, List <Product_OrderDTO> expectedProductsOrder)
        {
            _mock.Setup(orderHelper => orderHelper.UpdateOrder(expectedProductsOrder, expectedOrder, feedbackDtos)).Verifiable();

            _controller.UpdateOrder(newOrderInfo, 0, feedbackModels);

            _mock.Verify();
        }
Ejemplo n.º 3
0
        public void UpdateOrder(NewOrderInfoModel newOrderInfoModel, int orderId, List <FeedbackModel> feedbackModels)
        {
            if (newOrderInfoModel.ProductsInOrder.Count > 0)
            {
                var    config = new MapperConfiguration(cfg => cfg.CreateMap <NewOrderInfoModel, OrderDTO>());
                Mapper mapper = new Mapper(config);

                OrderDTO order = mapper.Map <OrderDTO>(newOrderInfoModel);
                order.Id = orderId;

                List <ProductInOrderModel> productInOrderModels = newOrderInfoModel.ProductsInOrder;

                config = new MapperConfiguration(
                    cfg => cfg
                    .CreateMap <ProductInOrderModel, ProductDTO>()
                    .ForMember(dest => dest.Id, option => option.MapFrom(source => source.ProductId))
                    .ForMember(dest => dest.Title, option => option.MapFrom(source => source.ProductTitle))
                    .ForMember(dest => dest.MeasureId, option => option.MapFrom(source => source.MeasureUnitId))
                    );
                mapper = new Mapper(config);

                List <ProductDTO> products = mapper.Map <List <ProductDTO> >(productInOrderModels);

                config = new MapperConfiguration(cfg => cfg.CreateMap <ProductInOrderModel, Product_OrderDTO>());
                mapper = new Mapper(config);

                List <Product_OrderDTO> productsOrder = mapper.Map <List <Product_OrderDTO> >(productInOrderModels);
                foreach (Product_OrderDTO p in productsOrder)
                {
                    p.OrderId = orderId;
                }

                config = new MapperConfiguration(cfg => cfg.CreateMap <FeedbackModel, FeedbackDTO>());
                mapper = new Mapper(config);

                List <FeedbackDTO> feedbackDTOs = mapper.Map <List <FeedbackDTO> >(feedbackModels);

                _ordersHelper.UpdateOrder(productsOrder, order, feedbackDTOs);
            }
            else
            {
                throw new ArgumentException("Product list is empty!");
            }
        }
Ejemplo n.º 4
0
        public void GetDTOsFromNewOrderInfoModel_WhenValidTestPassed_ShouldReturnDTOs(NewOrderInfoModel newOrderInfo,
                                                                                      List <FeedbackModel> feedbackModels, List <FeedbackDTO> feedbackDtos,
                                                                                      OrderDTO expectedOrder, List <Product_OrderDTO> expectedProductsOrder)
        {
            _mock.Setup(orderHelper => orderHelper.AddOrder(expectedProductsOrder, expectedOrder)).Returns(1);
            _mock.Setup(orderHelper => orderHelper.AddOrder(expectedProductsOrder, expectedOrder)).Verifiable();

            _mock.Setup(orderHelper => orderHelper.AddFeedbacks(feedbackDtos)).Verifiable();

            _controller.AddOrder(newOrderInfo);

            _mock.Verify();
        }