public async Task <SaveOrderOutput> SaveOrder(SaveOrderInput orderInfo)
        {
            Order order;

            if (orderInfo.Id.HasValue)
            {
                order = await _orderRepository.GetAsync(orderInfo.Id.Value);

                order = orderInfo.MapTo(order);
                await _orderRepository.UpdateAsync(order);

                foreach (OrderProductInput newOrderProduct in orderInfo.OrderProducts.Where(x => !x.Id.HasValue))
                {
                    OrderProduct orderProduct = newOrderProduct.MapTo <OrderProduct>();
                    await _orderProductRepository.InsertAsync(orderProduct);
                }
                foreach (OrderProduct deletedOrderProduct in order.Products.Where(x => orderInfo.OrderProducts.All(p => !p.Id.HasValue || p.Id.Value != x.Id)))
                {
                    await _orderProductRepository.DeleteAsync(deletedOrderProduct.Id);
                }
                foreach (OrderProductInput updatedOrderProduct in orderInfo.OrderProducts.Where(x => x.Id.HasValue && x.IsUpdatedRecord))
                {
                    OrderProduct orderProduct = await _orderProductRepository.GetAsync(updatedOrderProduct.Id.Value);

                    orderProduct = updatedOrderProduct.MapTo(orderProduct);
                    await _orderProductRepository.UpdateAsync(orderProduct);
                }
                await CurrentUnitOfWork.SaveChangesAsync();

                order = await _orderRepository.GetAsync(orderInfo.Id.Value);
            }
            else
            {
                order             = orderInfo.MapTo <Order>();
                order.CreatedDate = Clock.Now;
                order.Products    = orderInfo.OrderProducts.MapTo <List <OrderProduct> >();
                await _orderRepository.InsertAndGetIdAsync(order);
            }

            return(new SaveOrderOutput {
                Order = order.MapTo <OrderOutput>()
            });
        }