Beispiel #1
0
        public IList <FreightDto> GetFreight(GetFreightInputDto inputDto)
        {
            var weightShoppingCart  = calculateWeightShoppingCart(inputDto);
            var tenantExpeditions   = _tenantExpeditionRepo.GetAllList(i => i.IsActive);
            var originDistrict      = GetCurrentTenant().District;
            var destinationDistrict = _districtRepo.FirstOrDefault(i => i.Id == inputDto.DistrictId);

            var activeExpeditionServices = tenantExpeditions.Select(i => i.ExpeditionService).ToList();
            var activeExpeditions        = new List <Expedition>();

            activeExpeditionServices.ForEach(i =>
            {
                if (!activeExpeditions.Any(activeExpedition => activeExpedition.Id == i.Expedition.Id))
                {
                    activeExpeditions.Add(i.Expedition);
                }
            });

            var getShippingCostInputDto = new GetShippingCostInputDto
            {
                Expeditions = activeExpeditions,
                Origin      = originDistrict,
                Destination = destinationDistrict,
                Weight      = weightShoppingCart
            };

            IList <FreightDto> result = new List <FreightDto>();
            var rajaOngkirResponses   = _rajaOngkirService.GetShippingCost(getShippingCostInputDto);

            foreach (var rajaOngkirResponse in rajaOngkirResponses)
            {
                foreach (var rajaOngkirResponseResult in rajaOngkirResponse.Results)
                {
                    if (activeExpeditionServices.Any(i => i.Expedition.RajaOngkirCode.ToLower() == rajaOngkirResponse.Code.ToLower() && i.RajaOngkirCode.ToLower() == rajaOngkirResponseResult.ServiceName.ToLower()))
                    {
                        var expeditionService     = activeExpeditionServices.FirstOrDefault(i => i.Expedition.RajaOngkirCode.ToLower() == rajaOngkirResponse.Code.ToLower() && i.RajaOngkirCode.ToLower() == rajaOngkirResponseResult.ServiceName.ToLower());
                        var estimatedTimeDelivery = new EstimatedTimeDelivery(rajaOngkirResponseResult.EstimatedToDelivery);
                        var freightDto            = new FreightDto()
                        {
                            ExpeditionServiceId = expeditionService.Id,
                            ExpeditionFullName  = expeditionService.FullName,
                            Cost = rajaOngkirResponseResult.Cost,
                            EstimatedTimeDelivery      = estimatedTimeDelivery,
                            Description                = estimatedTimeDelivery.GetEstimatedTimeDeliverySentence(DateTime.Now),
                            TotalWeight                = weightShoppingCart,
                            ExpeditionServiceGroupName = expeditionService.GroupName
                        };
                        result.Add(freightDto);
                    }
                }
            }

            return(result);
        }
Beispiel #2
0
        public FreightDto GetFreightByExpeditionService(GetFreightByServiceInputDto inputDto)
        {
            var tenantExpedition = _tenantExpeditionRepo.FirstOrDefault(i => i.ExpeditionService.Id == inputDto.ExpeditionService.Expedition.Id);

            Validate.Found(tenantExpedition, "Expedition");
            if (!tenantExpedition.IsActive)
            {
                throw new HozaruException("Expedition tidak aktif");
            }

            var getShippingCostInputDto = new GetShippingCostInputDto
            {
                Expeditions = new List <Expedition>()
                {
                    inputDto.ExpeditionService.Expedition
                },
                Origin      = inputDto.Origin,
                Destination = inputDto.Destination,
                Weight      = inputDto.Weight
            };

            var rajaOngkirResponses = _rajaOngkirService.GetShippingCost(getShippingCostInputDto);

            if (rajaOngkirResponses.IsNullOrEmpty())
            {
                throw new HozaruException("Ongkos Kirim tidak ditemukan");
            }
            var rajaOngkirResponseResult = rajaOngkirResponses.FirstOrDefault().Results.FirstOrDefault(i => i.ServiceName.ToLower() == inputDto.ExpeditionService.RajaOngkirCode.ToLower());

            var estimatedTimeDelivery = new EstimatedTimeDelivery(rajaOngkirResponseResult.EstimatedToDelivery);
            var freightDto            = new FreightDto()
            {
                ExpeditionServiceId = inputDto.ExpeditionService.Id,
                ExpeditionFullName  = inputDto.ExpeditionService.FullName,
                Cost = rajaOngkirResponseResult.Cost,
                EstimatedTimeDelivery = estimatedTimeDelivery,
                Description           = estimatedTimeDelivery.GetEstimatedTimeDeliverySentence(DateTime.Now),
                TotalWeight           = inputDto.Weight
            };

            return(freightDto);
        }
Beispiel #3
0
 public OrderShipment(ExpeditionService expeditionService, decimal shippingCost, EstimatedTimeDelivery estimatedDelivery)
     : this()
 {
     this.ExpeditionService     = expeditionService;
     this.ShippingCost          = shippingCost;
     this.EstimatedTimeDelivery = estimatedDelivery;
 }