public IResult Execute(DeliveryRequestInfo input)
        {
            ShippingDetailInfo data   = new ShippingDetailInfo();
            IResult            status = null;

            try
            {
                // Translate
                data.DestinationAddress = input.Dest;
                data.OriginAddress      = input.Origin;
                data.Id = Convert.ToInt64(input.Id);

                // Translate Package Type
                switch (input.Type[0])
                {
                case 'L':
                    data.PackageInfo = PackageInfoFactory.GetLetterPackageInstance(input.LType);
                    break;

                case 'B':
                    data.PackageInfo = PackageInfoFactory.GetBoxPackageInstance(Convert.ToInt32(input.Height), Convert.ToInt32(input.Width), Convert.ToInt32(input.Depth));
                    break;

                default:
                    throw new FormatException("The Type must start with 'L' or 'B' only.");
                }


                // Translate Delivery Type
                switch (input.Type[1])
                {
                case 'A':
                    data.DeliveryMethod = DeliveryMethodEnum.Air;
                    break;

                case 'G':
                    data.DeliveryMethod = DeliveryMethodEnum.Ground;
                    break;

                default:
                    throw new FormatException("The second character in Type must be 'A' or 'G' only.");
                }
            }
            catch (Exception e)
            {
                status = ResultFactory.GetFailResultInstance(e.Message);
            }


            if (status == null)
            {
                JustInTimeShippingFacade controller = JustInTimeShippingFacade.GetInstance();
                status = controller.Execute(data);
            }

            return(status);
        }
Beispiel #2
0
 public IResult Validate(string input)
 {
     if (!string.IsNullOrEmpty(input))
     {
         return(ResultFactory.GetSuccessResultInstance());
     }
     else
     {
         return(ResultFactory.GetFailResultInstance("Delivery type can't be blank"));
     }
 }
 public IResult Validate(string input)
 {
     if (input.Length == 5 && Regex.Match(input, pattern).Success)
     {
         return(ResultFactory.GetSuccessResultInstance());
     }
     else
     {
         return(ResultFactory.GetFailResultInstance("Postcode must be 5 digit only."));
     }
 }
Beispiel #4
0
        public IResult Validate(AddressInfo input)
        {
            if (String.IsNullOrEmpty(input.Name) ||
                String.IsNullOrEmpty(input.Street) ||
                String.IsNullOrEmpty(input.City) ||
                String.IsNullOrEmpty(input.State) ||
                String.IsNullOrEmpty(input.PostalCode))
            {
                return(ResultFactory.GetFailResultInstance("One of the address field is not being fill up."));
            }

            return(ResultFactory.GetSuccessResultInstance());
        }
        public IResult Validate(PackageInfo input)
        {
            if (input.PackageType == PackageTypeEnum.Box && input.Weight > 0)
            {
                if ((input.BoxInfo.Height <= 0) &&
                    (input.BoxInfo.Width <= 0) &&
                    (input.BoxInfo.Depth <= 0))
                {
                    return(ResultFactory.GetFailResultInstance("All dimension of boxes must be greater than 0"));
                }
            }


            if (input.Weight <= 0)
            {
                return(ResultFactory.GetFailResultInstance("Please weight your package"));
            }

            return(ResultFactory.GetSuccessResultInstance());
        }
Beispiel #6
0
        public IResult Execute(ShippingDetailInfo input)
        {
            string path = String.Format("C:\\TEMP\\ShippingDetails-{0}.xml", input.Id);

            using (FileStream fs = File.Open(path, FileMode.Create, FileAccess.ReadWrite))
            {
                using (TextWriter WriteFileStream = new StreamWriter(fs))
                {
                    try
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(ShippingDetailInfo));
                        serializer.Serialize(WriteFileStream, input);
                    }
                    catch (Exception e)
                    {
                        return(ResultFactory.GetFailResultInstance(e.Message));
                    }
                }
            }

            return(ResultFactory.GetSuccessWithMessageResultInstance(path));;
        }
        public IResult Execute(ShippingDetailInfo detail)
        {
            StringBuilder strBuilder         = new StringBuilder();
            AddressInfo   originAddress      = detail.OriginAddress;
            AddressInfo   destinationAddress = detail.DestinationAddress;
            string        msg    = String.Empty;
            bool          status = false;
            string        xmlFile;

            try
            {
                detail.PackageInfo.Weight = WeightAdapterFactory.GetInstance().GetWeightAdapterInstance(WeightAdapterEnum.SAM).GetWeight();
                detail  = new DeliveryTimeCommand().Execute(detail);
                detail  = new ShippingCostCommand().Execute(detail);
                xmlFile = new XmlPersistantCommand().Execute(detail).Message;

                IResult originAddressValidation  = new AddressValidator().Validate(originAddress);
                IResult originPostCodeValidation = new PostCodeValidator().Validate(originAddress.PostalCode);
                IResult destAddressValidation    = new AddressValidator().Validate(destinationAddress);
                IResult destPostCodeValidation   = new PostCodeValidator().Validate(destinationAddress.PostalCode);
                IResult deliveryTypeValidation   = new DeliveryTypeValidator().Validate(detail.DeliveryMethod.ToString());
                IResult packageInfoValidation    = new PackageInfoValidator().Validate(detail.PackageInfo);


                if (originAddressValidation.IsSuccess &&
                    originPostCodeValidation.IsSuccess &&
                    destAddressValidation.IsSuccess &&
                    destPostCodeValidation.IsSuccess &&
                    deliveryTypeValidation.IsSuccess &&
                    packageInfoValidation.IsSuccess)
                {
                    strBuilder.AppendLine("Id: " + detail.Id);
                    strBuilder.AppendLine("Package Type: " + detail.PackageInfo.PackageType.ToString());
                    if (detail.PackageInfo.PackageType == PackageTypeEnum.Box)
                    {
                        strBuilder.AppendLine("Height: " + detail.PackageInfo.BoxInfo.Height);
                        strBuilder.AppendLine("Width: " + detail.PackageInfo.BoxInfo.Width);
                        strBuilder.AppendLine("Depth: " + detail.PackageInfo.BoxInfo.Depth);
                        strBuilder.AppendLine("Is insured? :" + detail.IsInsured);
                    }
                    else
                    {
                        strBuilder.AppendLine("Letter Type: " + detail.PackageInfo.LetterInfo.LetterProofType.ToString());
                    }
                    strBuilder.AppendLine("Weight: " + detail.PackageInfo.Weight + " Ounce");
                    strBuilder.AppendLine("");
                    strBuilder.AppendLine("Origin:");
                    strBuilder.AppendLine("=======");
                    strBuilder.AppendLine("Name:       " + originAddress.Name);
                    strBuilder.AppendLine("Street:     " + originAddress.Street);
                    strBuilder.AppendLine("City:       " + originAddress.City);
                    strBuilder.AppendLine("State:      " + originAddress.State);
                    strBuilder.AppendLine("Postal Code:" + originAddress.PostalCode);
                    strBuilder.AppendLine("");
                    strBuilder.AppendLine("Destination:");
                    strBuilder.AppendLine("===========");
                    strBuilder.AppendLine("Name:       " + destinationAddress.Name);
                    strBuilder.AppendLine("Street:     " + destinationAddress.Street);
                    strBuilder.AppendLine("City:       " + destinationAddress.City);
                    strBuilder.AppendLine("State:      " + destinationAddress.State);
                    strBuilder.AppendLine("Postal Code:" + destinationAddress.PostalCode);
                    strBuilder.AppendLine("");
                    strBuilder.AppendLine("Delivery Type: " + detail.DeliveryMethod.ToString());
                    strBuilder.AppendLine("Delivery Time: " + detail.DeliveryTime.ToString() + " days");
                    strBuilder.AppendLine("Delivery Cost: " + String.Format("{0:C2}", detail.Cost));

                    status = true;
                }
                if (!originAddressValidation.IsSuccess || !destAddressValidation.IsSuccess)
                {
                    if (!originAddressValidation.IsSuccess)
                    {
                        strBuilder.AppendLine("Origin Address     : " + originAddressValidation.Message);
                    }
                    if (!destAddressValidation.IsSuccess)
                    {
                        strBuilder.AppendLine("Destination Address: " + destAddressValidation.Message);
                    }
                }
                if (!originPostCodeValidation.IsSuccess || !destPostCodeValidation.IsSuccess)
                {
                    if (!originPostCodeValidation.IsSuccess)
                    {
                        strBuilder.AppendLine("\nOrigin Address     : " + originPostCodeValidation.Message);
                    }
                    if (!destPostCodeValidation.IsSuccess)
                    {
                        strBuilder.AppendLine("\nDestination Address: " + destPostCodeValidation.Message);
                    }
                }
                if (!deliveryTypeValidation.IsSuccess)
                {
                    strBuilder.AppendLine("Delivery Type: " + deliveryTypeValidation.Message);
                }
                if (!packageInfoValidation.IsSuccess)
                {
                    strBuilder.AppendLine("Package Information: " + packageInfoValidation.Message);
                }

                msg = strBuilder.ToString();
            }
            catch (Exception e)
            {
                status = false;
                msg    = e.Message;
            }

            return(status ? ResultFactory.GetSuccessWithMessageResultInstance(msg) : ResultFactory.GetFailResultInstance(msg));
        }