private Action CreateAction(RTTTripDetails details, Consignment consignment, RttSiteDefault site)
        {
            var action = new Action
            {
                Id = utils.CreateActionId(consignment, site),
                InternalReference = consignment.ConsignmentID.ToString(),
                Reference         = consignment.ConsignmentNo?.Trim(),
                CreatedOn         = details.TripDate.GetValueOrDefault(),
                ExpectedDelivery  = details.TripDate,
                ClientId          = site.Id,
                CustomerReference = consignment.Account.Acc_Id.ToString(),
                CustomerCode      = consignment.Account.AccountNo?.Trim(),
                IsCod             = false,
                AmountIncl        = 0,
                Nature            = EActionNature.Product,
                Weight            = consignment.Parcels.Sum(p => p.ActualKG),
                Pieces            = consignment.Parcels.Count,
                Volume            = consignment.Parcels.Sum(p => p.Length * p.Height * p.Width),
                VolumetricMass    = consignment.Parcels.Sum(p => p.VolumizerKG),
                HandlingUnitIds   = consignment.Parcels.Select(p => $"{site.Id}/unit/{p.ParcelID?.Trim()}").ToList(),
            };

            if (consignment.Parcels.Count == 0)
            {
                action.ActionTypeId   = site.RttActionTypeCollection;
                action.ActionTypeName = "Collection";
            }
            else
            {
                action.ActionTypeId   = site.RttActionTypeDelivery;
                action.ActionTypeName = "Delivery";
            }

            return(action);
        }
        private Action CreateGroupAction(RTTTripDetails details, IGrouping <string, Consignment> group, RttSiteDefault site)
        {
            var action = new Action
            {
                Id = CreateActionId(group, site),
                InternalReference = group.Select(x => x.ConsignmentID).FirstOrDefault().ToString(),
                Reference         = group.Select(x => GetGroupId(x)).FirstOrDefault().ToString(),
                CreatedOn         = details.TripDate.GetValueOrDefault(),
                ExpectedDelivery  = details.TripDate,
                ClientId          = site.Id,
                CustomerReference = group.Select(x => x.ConsignmentID).FirstOrDefault().ToString(),
                CustomerCode      = group.Select(x => x.Address.Addr_id).FirstOrDefault().ToString(),
                IsCod             = false,
                AmountIncl        = 0,
                Nature            = EActionNature.Product,
                Weight            = group.Sum(x => x.Parcels.Select(y => y.ActualKG).Sum()),
                Pieces            = group.Select(x => x.TotalParcelCount).Sum(),
                VolumetricMass    = group.Sum(x => x.Parcels.Select(y => y.VolumizerKG).Sum()),
                HandlingUnitIds   = HandleGroup(group, site),
                Direction         = EActionDirection.Outbound
            };

            if (group.Select(x => x).FirstOrDefault().IsCollection())
            {
                action.ActionTypeId   = site.RttActionTypeCollection;
                action.ActionTypeName = "Collection";
            }
            else
            {
                action.ActionTypeId   = site.RttActionTypeDelivery;
                action.ActionTypeName = "Delivery";
            }

            return(action);
        }
        public static Trackmatic.Rest.Routing.Model.Action CreateRouteAction(SiteData _site, ActionItem action)
        {
            var routeBuilderAction = new Trackmatic.Rest.Routing.Model.Action
            {
                Id                = AsId(_site.Id, action.GetActionReference()),
                Reference         = action.GetActionReference(),
                CustomerReference = action.GetCustomerReference(),
                InternalReference = action.GetInternalReference(),
                ActionTypeId      = action.GetActionTypeId(),
                ActionTypeName    = action.GetNature(),
                ExpectedDelivery  = action.GetExpectedDeliveryDate(),
                ReceivedOn        = DateTime.UtcNow,
                Direction         = EActionDirection.Outbound,//action.DetermineDirection(),
                Nature            = EActionNature.Product,
                ClientId          = _site.Id,
                Instructions      = action.GetSpecialInstructions(),
                CreatedOn         = action.GetCreatedOn(),
            };

            return(routeBuilderAction);
        }