Exemplo n.º 1
0
        public int Add(CustomerOrderDto customerOrderDto)
        {
            var customerOrderEntity    = Mapper.Map <CustomerOrderDto, CustomerOrder>(customerOrderDto);
            var addCustomerOrderResult = _repo.Add(customerOrderEntity);

            return(addCustomerOrderResult);
        }
Exemplo n.º 2
0
        public int Update(CustomerOrderDto customerOrderDto)
        {
            var customerOrderEntity       = Mapper.Map <CustomerOrderDto, CustomerOrder>(customerOrderDto);
            var updateCustomerOrderResult = _repo.Update(customerOrderEntity);

            return(updateCustomerOrderResult);
        }
Exemplo n.º 3
0
 public IActionResult CreateCustomerOrder([FromBody] CustomerOrderDto dto)
 {
     try
     {
         return(Ok(_customerOrderServices.CreateOrder(dto)));
     }
     catch (ArgumentException e)
     {
         return(BadRequest(e.Message));
     }
 }
Exemplo n.º 4
0
 public override bool Equals(object obj)
 {
     if (obj is CustomerOrderDto)
     {
         CustomerOrderDto other = (CustomerOrderDto)obj;
         return(CustomerId.Equals(other.CustomerId) && OrderId == other.OrderId);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 5
0
        public IHttpActionResult GetOrders(int customerId)
        {
            var cancelledOrders = _context.Orders
                                  .Where(o => o.CustomerId == customerId)
                                  .Where(o => o.OrderStatus == Constants.OrderStatus.CANCELLED.ToString())
                                  .OrderBy(o => o.OrderDateTime)
                                  .ToList();

            List <string> statusList = new List <string>
            {
                Constants.OrderStatus.COMPLETED.ToString(),
                          Constants.OrderStatus.CANCELLED.ToString()
            };

            var completedOrders = _context.Orders
                                  .Where(o => o.CustomerId == customerId)
                                  .Where(o => statusList.Contains(o.OrderStatus))
                                  .OrderBy(o => o.OrderDateTime)
                                  .ToList();
            List <CustomerOrderDto> completedOrderDtos = new List <CustomerOrderDto>();

            foreach (var order in completedOrders)
            {
                var customerOrder = new CustomerOrderDto();
                customerOrder = Mapper.Map <Order, CustomerOrderDto>(order);
                var hasCustomerRating = _context.TruckOwnerRatings.SingleOrDefault(t => t.OrderId == order.OrderId);
                if (hasCustomerRating != null)
                {
                    customerOrder.HasCustomerRating = true;
                }
                completedOrderDtos.Add(customerOrder);
            }

            var runningOrders = _context.Orders
                                .Where(o => o.CustomerId == customerId)
                                .Where(o => o.OrderStatus != Constants.OrderStatus.CANCELLED.ToString())
                                .Where(o => o.OrderStatus != Constants.OrderStatus.COMPLETED.ToString())
                                .OrderBy(o => o.OrderDateTime)
                                .ToList();

            GetCustomerOrderListDto ordersList = new GetCustomerOrderListDto
            {
                RunningOrders   = runningOrders.Select(Mapper.Map <Order, CustomerOrderDto>),
                CompletedOrders = completedOrderDtos,
                CancelledOrders = cancelledOrders.Select(Mapper.Map <Order, CustomerOrderDto>)
            };

            return(Ok(ordersList));
        }
        public async Task <IActionResult> GetCustomerLastOrder([FromBody] CustomerDto customerDto)
        {
            try
            {
                //get customerDetails from API
                var customerDetailsDto = await _customerService.GetCustomerDetails(customerDto.User);


                //match customer email and id
                if (customerDetailsDto.CustomerId != customerDto.CustomerId)
                {
                    return(BadRequest("CustomerId does not match."));
                }

                //get orders
                var orderDto = await _orderService.GetOrder(customerDetailsDto.CustomerId);

                //get customer details
                var customerOrderDto = new CustomerOrderDto();
                customerOrderDto.Customer.FirstName = customerDetailsDto.FirstName;
                customerOrderDto.Customer.LastName  = customerDetailsDto.LastName;

                if (orderDto != null)
                {
                    orderDto.DeliveryAddress = customerDetailsDto.HouseNumber + " " + customerDetailsDto.Street + ", " + customerDetailsDto.Town + ", " + customerDetailsDto.Postcode;
                }


                customerOrderDto.Order = orderDto;

                //return dto
                return(Ok(customerOrderDto));
            }
            catch (Exception ex)
            {
                //500 - Internal Server Error
                return(StatusCode(500, ex.Message));
            }
        }
Exemplo n.º 7
0
        public void TestTakeNested()
        {
            IEnumerable <CustomerOrderDto> actual   = Partitioning.TakeNested();
            IEnumerable <CustomerOrderDto> expected =
                new CustomerOrderDto[]
            {
                new CustomerOrderDto()
                {
                    CustomerId = "LAZYK", OrderId = 10482
                },
                new CustomerOrderDto()
                {
                    CustomerId = "LAZYK", OrderId = 10545
                },
                new CustomerOrderDto()
                {
                    CustomerId = "TRAIH", OrderId = 10574
                }
            };

            CollectionAssert.AreEqual(actual.ToList(), expected.ToList(), "You failed!");
        }
Exemplo n.º 8
0
        public Guid CreateOrder(CustomerOrderDto dto)
        {
            var customer = _customerRepository.GetById(dto.CustomerId);

            if (customer == null)
            {
                throw new ArgumentException("Customer not found.");
            }

            var order = CustomerOrder.MakeCustomerOrder(dto.RegisterNumber, customer);

            var products = _productRepository
                           .FindBy(p => dto.Items
                                   .Select(r => r.ProductId)
                                   .Contains(p.Id))
                           .AsEnumerable();

            dto.Items
            .ForEach(i => order.AddItem(products.FirstOrDefault(p => p.Id.Equals(i.ProductId)), i.Amount));

            _repository.Add(order);

            return(order.Id);
        }
Exemplo n.º 9
0
 public ActionResult <int> Put(int id, [FromBody] CustomerOrderDto customerOrderDto)
 {
     return(_customerOrderService.Update(customerOrderDto));
 }
Exemplo n.º 10
0
 public ActionResult <int> Post([FromBody] CustomerOrderDto customerOrderDto)
 {
     return(_customerOrderService.Add(customerOrderDto));
 }
Exemplo n.º 11
0
        public void TestSelectMany()
        {
            IEnumerable <CustomerOrderDto> actual   = Projection.SelectMany();
            IEnumerable <CustomerOrderDto> expected =
                new CustomerOrderDto[] {
                new CustomerOrderDto()
                {
                    CustomerId = "LAZYK", OrderId = 10482
                },
                new CustomerOrderDto()
                {
                    CustomerId = "LAZYK", OrderId = 10545
                },
                new CustomerOrderDto()
                {
                    CustomerId = "TRAIH", OrderId = 10574
                },
                new CustomerOrderDto()
                {
                    CustomerId = "TRAIH", OrderId = 10577
                },
                new CustomerOrderDto()
                {
                    CustomerId = "TRAIH", OrderId = 10822
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10469
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10483
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10504
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10596
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10693
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10696
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10723
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10740
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10861
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10904
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 11032
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 11066
                }
            };

            CollectionAssert.AreEqual(actual.ToList(), expected.ToList(), "You failed!");
        }
Exemplo n.º 12
0
        public void TestSkipNested()
        {
            IEnumerable <CustomerOrderDto> actual   = Partitioning.SkipNested();
            IEnumerable <CustomerOrderDto> expected =
                new CustomerOrderDto[]
            {
                new CustomerOrderDto()
                {
                    CustomerId = "TRAIH", OrderId = 10574
                },
                new CustomerOrderDto()
                {
                    CustomerId = "TRAIH", OrderId = 10577
                },
                new CustomerOrderDto()
                {
                    CustomerId = "TRAIH", OrderId = 10822
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10269
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10344
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10469
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10483
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10504
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10596
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10693
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10696
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10723
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10740
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10861
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 10904
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 11032
                },
                new CustomerOrderDto()
                {
                    CustomerId = "WHITC", OrderId = 11066
                }
            };

            CollectionAssert.AreEqual(actual.ToList(), expected.ToList(), "You failed!");
        }