Ejemplo n.º 1
0
 public ParcelMetadata(ParcelType parcelType, decimal cost, decimal wightLimit, decimal overweightCost)
 {
     ParcelType     = parcelType;
     Cost           = cost;
     WightLimit     = wightLimit;
     OverweightCost = overweightCost;
 }
Ejemplo n.º 2
0
        private static Parcel GetParcel()
        {
            GetEstateBasicInfo(out string address, out decimal width, out decimal length, out decimal price, out OwnerType owner);

            ParcelType parcelType = Validator.AskParcelType("Rodzaj działki (R - Rolna; B - Budowlana): ");

            return(new Parcel(address, width, length, price, owner, parcelType, DateTime.Now));
        }
Ejemplo n.º 3
0
 private ParcelTypes mapToEntity(ParcelType obj, ParcelTypes entity)
 {
     entity.Id        = obj.Id;
     entity.Supported = obj.Supported;
     entity.Fee       = obj.Fee;
     entity.Type      = obj.Type;
     return(entity);
 }
Ejemplo n.º 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            ParcelType type = db.ParcelTypes.Find(id);

            db.ParcelTypes.Remove(type);
            db.SaveChanges();
            TempData["SuccessMsg"] = "You have successfully Deleted Parcel Type.";
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        private ParcelType mapFromEntity(ParcelTypes entity)
        {
            ParcelType obj = new ParcelType();

            obj.Id        = entity.Id;
            obj.Supported = entity.Supported;
            obj.Fee       = entity.Fee;
            obj.Type      = entity.Type;
            return(obj);
        }
Ejemplo n.º 6
0
 public Parcel(int lengthMm, int breadthMm, int heightMm, decimal weightKg)
 {
     ValidateParameters(lengthMm, heightMm, breadthMm, weightKg);
     this.LengthMm   = lengthMm;
     this.HeightMm   = heightMm;
     this.BreadthMm  = breadthMm;
     this.WeightKg   = weightKg;
     this.ParcelType = CalculateType();
     this.CostNzd    = CalculateCost();
 }
Ejemplo n.º 7
0
        public void Morehan25Kg_WontFindParcel()
        {
            int           lenght    = 1;
            int           breadth   = 1;
            int           height    = 1;
            double        weight    = 26;
            ParcelService obj       = new ParcelService(lenght, breadth, height, weight);
            ParcelType    resultobj = new ParcelType();

            resultobj = obj.CalculateParcelCost();
            Assert.AreEqual(resultobj._type, string.Empty);
            Assert.AreEqual <decimal>(resultobj._cost, 0);
        }
Ejemplo n.º 8
0
        public void TooBigHeight_WontFindPackage()
        {
            int           lenght    = 900;
            int           breadth   = 300;
            int           height    = 900;
            double        weight    = 20;
            ParcelService obj       = new ParcelService(lenght, breadth, height, weight);
            ParcelType    resultobj = new ParcelType();

            resultobj = obj.CalculateParcelCost();
            Assert.AreEqual(resultobj._type, string.Empty);
            Assert.AreEqual <decimal>(resultobj._cost, 0);
        }
Ejemplo n.º 9
0
        public void FindMediumPackage()
        {
            int           lenght    = 300;
            int           breadth   = 400;
            int           height    = 200;
            double        weight    = 20;
            ParcelService obj       = new ParcelService(lenght, breadth, height, weight);
            ParcelType    resultobj = new ParcelType();

            resultobj = obj.CalculateParcelCost();
            Assert.AreEqual <string>(resultobj._type, Constants.MEDIUM_Type);
            Assert.AreEqual <decimal>(resultobj._cost, Constants.MEDIUM_COST);
        }
Ejemplo n.º 10
0
        public ActionResult Edit(ParcelTypeVM a)
        {
            ParcelType d = new ParcelType();

            d.ParcelTypeID = a.DescID;
            d.ParcelType1  = a.Description;
            d.ID           = a.id;

            db.Entry(d).State = EntityState.Modified;
            db.SaveChanges();
            TempData["SuccessMsg"] = "You have successfully Updated Parcel Type.";

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 11
0
        public void TestSizeCharge(int height, int width, int length, ParcelType type, decimal cost)
        {
            // arrange
            var parcel = new Parcel(height, width, length, 0);

            // act
            var calc         = new CostCalculator();
            var parcelCharge = calc.CalculateCharges(new List <Parcel>()
            {
                parcel
            }).Charges.First();

            // assert
            Assert.AreEqual(cost, parcelCharge.TotalCharge);
            Assert.AreEqual(type, parcelCharge.Type);
        }
        public void Given_ParcelWithHeavyWeight_Should_ReturnValidResultWithCorrectParcelTypeDefinition(
            decimal dimension, decimal weight, ParcelType expectedParcelType, decimal expectedCost,
            decimal expectedWeightLimit, decimal expectedOverweightCost)
        {
            //Arrange
            var sut    = new ParcelMetadataProvider();
            var parcel = new Parcel(dimension, dimension, dimension, weight);

            //Act
            var result = sut.ResolveParcelMetadata(parcel);

            //Assert
            result.Should().NotBeNull();
            result.Cost.Should().Be(expectedCost);
            result.ParcelType.Should().Be(expectedParcelType);
            result.WightLimit.Should().Be(expectedWeightLimit);
            result.OverweightCost.Should().Be(expectedOverweightCost);
        }
Ejemplo n.º 13
0
        public ActionResult Create(ParcelTypeVM c)
        {
            ParcelType obj = new ParcelType();
            int        max = (from a in db.ParcelTypes orderby a.ID descending select a.ID).FirstOrDefault();

            max = max + 1;

            obj.ID           = max;
            obj.ParcelTypeID = c.DescID;
            obj.ParcelType1  = c.Description;


            db.ParcelTypes.Add(obj);
            db.SaveChanges();
            TempData["SuccessMsg"] = "You have successfully added Parcel Type.";

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 14
0
        private static IParcel CreateParcel(ParcelType type)
        {
            switch (type)
            {
            case ParcelType.Small:
                return(new SmallParcel());

            case ParcelType.Medium:
                return(new MediumParcel());

            case ParcelType.Large:
                return(new LargeParcel());

            case ParcelType.XL:
                return(new XLParcel());

            default:
                return(new HeavyParcel());
            }
        }
Ejemplo n.º 15
0
        void formatInputOutput()
        {
            try
            {
                int           lenght    = Int32.Parse(txtLen.Text);
                int           breadth   = Int32.Parse(txtBrd.Text);
                int           height    = Int32.Parse(txtHgt.Text);
                double        weight    = Int32.Parse(txtwght.Text);
                ParcelService obj       = new ParcelService(lenght, breadth, height, weight);
                ParcelType    resultobj = new ParcelType();
                resultobj = obj.CalculateParcelCost();
                decimal resultCost = resultobj._cost;
                string  resultType = resultobj._type;

                if (resultType == string.Empty && resultCost == 0)
                {
                    Label3.Text           = "Invalid Item - Cannot find type and cost";
                    Label3.Visible        = true;
                    lblParcelType.Visible = false;
                    Label1.Visible        = false;
                    lblParcelCost.Visible = false;
                    Label2.Visible        = false;
                }

                else
                {
                    lblParcelType.Text    = resultType;
                    lblParcelType.Visible = true;
                    Label1.Visible        = true;
                    lblParcelCost.Text    = resultCost.ToString();
                    lblParcelCost.Visible = true;
                    Label2.Visible        = true;
                    Label3.Visible        = false;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 16
0
        public static ParcelEntity CreateParcel(ParcelType parcelType)
        {
            switch (parcelType)
            {
            case ParcelType.Large:
                ParcelEntity largeParcel = new ParcelEntity();
                largeParcel.Length  = Constants.LARGE_LENGTH;
                largeParcel.Breadth = Constants.LARGE_BREADTH;
                largeParcel.Height  = Constants.LARGE_HEIGHT;
                largeParcel.Weight  = Constants.MAX_WEIGHT;
                largeParcel.Cost    = Constants.LARGE_COST;
                largeParcel.Type    = ParcelType.Large;
                return(largeParcel);

            case ParcelType.Medium:
                ParcelEntity mediumParcel = new ParcelEntity();
                mediumParcel.Length  = Constants.MEDIUM_LENGTH;
                mediumParcel.Breadth = Constants.MEDIUM_BREADTH;
                mediumParcel.Height  = Constants.MEDIUM_HEIGHT;
                mediumParcel.Weight  = Constants.MAX_WEIGHT;
                mediumParcel.Cost    = Constants.MEDIUM_COST;
                mediumParcel.Type    = ParcelType.Medium;
                return(mediumParcel);

            case ParcelType.Small:
                ParcelEntity smallParcel = new ParcelEntity();
                smallParcel.Length  = Constants.SMALL_LENGTH;
                smallParcel.Breadth = Constants.SMALL_BREADTH;
                smallParcel.Height  = Constants.SMALL_HEIGHT;
                smallParcel.Weight  = Constants.MAX_WEIGHT;
                smallParcel.Cost    = Constants.SMALL_COST;
                smallParcel.Type    = ParcelType.Small;
                return(smallParcel);

            default:
                throw new InvalidParcelException("Invalid Parcel type");
            }
        }
Ejemplo n.º 17
0
        public void TestOverweightCharge(int weight, ParcelType type, decimal overweightCharge)
        {
            // arrange
            Dictionary <ParcelType, Parcel> testParcels = new Dictionary <ParcelType, Parcel>()
            {
                { ParcelType.Small, new Parcel(2, 2, 2, weight) },
                { ParcelType.Medium, new Parcel(20, 20, 20, weight) },
                { ParcelType.Large, new Parcel(70, 70, 70, weight) },
                { ParcelType.XL, new Parcel(120, 120, 120, weight) },
            };

            var parcel = testParcels[type];

            // act
            var calc = new CostCalculator();
            var res  = calc.CalculateCharges(new List <Parcel>()
            {
                parcel
            });

            // assert
            Assert.AreEqual(overweightCharge, res.Charges.First().OverweightSurcharge);
        }
Ejemplo n.º 18
0
 public ParcelDeliveryCost(string parcelName, ParcelType parcelType, decimal cost)
 {
     ParcelName = parcelName;
     ParcelType = parcelType;
     Cost       = cost;
 }
Ejemplo n.º 19
0
        public void GivenAParcelOfDefinedDimensions_WhenSetTypeByDimension_ThenCorrectTypeIsApplied(uint width, uint height, uint length, ParcelType expectedType)
        {
            var parcel = new Parcel
            {
                WidthInCentimeters  = width,
                HeightInCentimeters = height,
                LengthInCentimeters = length
            };

            parcel.SetTypeByDimension(Settings());
            parcel.Type.ShouldBe(expectedType);
            _testOutputHelper.WriteLine($"Parcel type: {parcel.Type}");
        }
        public void Given_ParcelWithSpecificSize_Should_ReturnValidResultWithCorrectParcelTypeDefinition(decimal width,
                                                                                                         decimal length, decimal height, ParcelType expectedParcelType, decimal expectedCost,
                                                                                                         decimal expectedWeightLimit)
        {
            //Arrange
            var sut    = new ParcelMetadataProvider();
            var parcel = new Parcel(width, length, height, 0);

            //Act
            var result = sut.ResolveParcelMetadata(parcel);

            //Assert
            result.Should().NotBeNull();
            result.Cost.Should().Be(expectedCost);
            result.ParcelType.Should().Be(expectedParcelType);
            result.WightLimit.Should().Be(expectedWeightLimit);
        }
Ejemplo n.º 21
0
 public NthFreeDiscountStrategy(int parcelCount, ParcelType parcelType)
 {
     _parcelType  = parcelType;
     _parcelCount = parcelCount;
 }
Ejemplo n.º 22
0
 public bool IsValid(Parcel parcel, ParcelType type)
 {
     return(_validators.All(x => x.IsValid(parcel, type)));
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Rate" /> class.
        /// </summary>
        /// <param name="alternateBaseCharge">alternateBaseCharge.</param>
        /// <param name="alternateTotalCharge">alternateTotalCharge.</param>
        /// <param name="baseCharge">baseCharge.</param>
        /// <param name="baseChargeTaxes">baseChargeTaxes.</param>
        /// <param name="carrier">carrier (required).</param>
        /// <param name="currencyCode">ISO-4217.</param>
        /// <param name="deliveryCommitment">deliveryCommitment.</param>
        /// <param name="destinationZone">destinationZone.</param>
        /// <param name="dimensionalWeight">dimensionalWeight.</param>
        /// <param name="discounts">discounts.</param>
        /// <param name="inductionPostalCode">inductionPostalCode.</param>
        /// <param name="parcelType">parcelType (required).</param>
        /// <param name="rateTypeId">rateTypeId.</param>
        /// <param name="serviceId">serviceId.</param>
        /// <param name="specialServices">specialServices.</param>
        /// <param name="surcharges">surcharges.</param>
        /// <param name="totalCarrierCharge">totalCarrierCharge.</param>
        /// <param name="totalTaxAmount">totalTaxAmount.</param>
        public Rate(decimal alternateBaseCharge = default(decimal), decimal alternateTotalCharge = default(decimal), decimal baseCharge = default(decimal), List <Tax> baseChargeTaxes = default(List <Tax>), Carrier carrier = default(Carrier), string currencyCode = default(string), DeliveryCommitment deliveryCommitment = default(DeliveryCommitment), decimal destinationZone = default(decimal), ParcelWeight dimensionalWeight = default(ParcelWeight), List <Discount> discounts = default(List <Discount>), string inductionPostalCode = default(string), ParcelType parcelType = default(ParcelType), string rateTypeId = default(string), Services?serviceId = default(Services?), List <SpecialService> specialServices = default(List <SpecialService>), List <Surcharge> surcharges = default(List <Surcharge>), decimal totalCarrierCharge = default(decimal), decimal totalTaxAmount = default(decimal))
        {
            // to ensure "carrier" is required (not null)
            if (carrier == null)
            {
                throw new InvalidDataException("carrier is a required property for Rate and cannot be null");
            }
            else
            {
                this.Carrier = carrier;
            }

            // to ensure "parcelType" is required (not null)
            if (parcelType == null)
            {
                throw new InvalidDataException("parcelType is a required property for Rate and cannot be null");
            }
            else
            {
                this.ParcelType = parcelType;
            }

            this.AlternateBaseCharge  = alternateBaseCharge;
            this.AlternateTotalCharge = alternateTotalCharge;
            this.BaseCharge           = baseCharge;
            this.BaseChargeTaxes      = baseChargeTaxes;
            this.CurrencyCode         = currencyCode;
            this.DeliveryCommitment   = deliveryCommitment;
            this.DestinationZone      = destinationZone;
            this.DimensionalWeight    = dimensionalWeight;
            this.Discounts            = discounts;
            this.InductionPostalCode  = inductionPostalCode;
            this.RateTypeId           = rateTypeId;
            this.ServiceId            = serviceId;
            this.SpecialServices      = specialServices;
            this.Surcharges           = surcharges;
            this.TotalCarrierCharge   = totalCarrierCharge;
            this.TotalTaxAmount       = totalTaxAmount;
        }
Ejemplo n.º 24
0
 public bool IsValid(Parcel parcel, ParcelType type)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 25
0
 public Parcel(int number, string address, decimal width, decimal length,
               decimal price, Owner owner, DateTime addedDate, ParcelType type)
     : base(number, address, width, length, price, owner, addedDate)
 {
     ParcelType = type;
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Example to Get available services, Add a shipment to the account and the book the collection
        /// </summary>
        public static void Main()
        {
            LoadConfiguration();

            int count = 0;

            ServiceType[] availableServices = null;

            try {
                // First we need to build a shipment request object
                ShipmentRequestType Shipment = new ShipmentRequestType();
                //shipment.ServiceID = null;
                //shipment.ClientReference = null;
                //shipment.FollowShipment = null;

                ParcelType Parcel = new ParcelType
                {
                    Height   = 10,  // This is cm
                    Length   = 10,  // This is cm
                    Width    = 10,  // This is cm
                    Weight   = 10,  // This is kg
                    Value    = 100, // This is GBP
                    Contents = "New Dress for Klingor"
                };


                // Obviously we could add more parcels here
                ParcelType[] Parcels = new ParcelType[1];
                Parcels[0] = Parcel;

                AddressType Address = new AddressType();

                // Receipient Details
                RecipientAddressType RecipientAddress = new RecipientAddressType
                {
                    RecipientName      = "Cprl Klingor",
                    RecipientEmail     = "*****@*****.**",
                    RecipientTelephone = "01522 76767676"
                };

                Address.CompanyName = "The SaleGroup";
                Address.Street      = "Unit 6 The Regatta";
                Address.Locality    = "Henley Way";
                Address.TownCity    = "Lincoln";
                Address.County      = "Lincolnshire";
                Address.PostalCode  = "LN6 3QR";
                Address.CountryCode = "GB";

                RecipientAddress.RecipientAddress = Address;

                // Senders details
                // Despatch bay lets you send parcels from an "Away Address",
                // but you could pull this from the account API, which is the preferred method
                SenderAddressType SenderAddress = new SenderAddressType
                {
                    SenderName      = "Hawkeye Pearce",
                    SenderEmail     = "*****@*****.**",
                    SenderTelephone = "01522 000000"
                };

                Address             = new AddressType(); // clear the address to reuse the object
                Address.Street      = "West Parade ";
                Address.TownCity    = "Lincoln";
                Address.PostalCode  = "LN1 1YP";
                Address.County      = "Lincolnshire";
                Address.CountryCode = "GB";

                SenderAddress.SenderAddress = Address;

                // Put the Shipment together
                Shipment.Parcels          = Parcels;
                Shipment.RecipientAddress = RecipientAddress;
                Shipment.SenderAddress    = SenderAddress;

                // Call the service
                availableServices = GetAvailableServicesMethod(Shipment);

                // iterate though the list of returned services
                count = 0;
                foreach (ServiceType element in availableServices)
                {
                    count += 1;
                    if (count == 1)
                    {
                        // Manually apply the First service
                        Shipment.ServiceID = element.ServiceID;

                        // Not sure why, but errors with ServiceID = 0
                        // if ServiceIDSpecified is Not set to true;
                        Shipment.ServiceIDSpecified = true;
                    }
                    System.Console.WriteLine("Service id:{0} - {1} £{2}", element.ServiceID, element.Name, element.Cost);
                }


                Shipment.ClientReference = "Dummy Client Ref";
                // We need a collection Date
                CollectionDateType CollectionDate = new CollectionDateType
                {
                    // Set the Collection date for tomorrow
                    CollectionDate = DateTime.Today.AddDays(1).ToString("yyyy-MM-dd")
                };

                Shipment.CollectionDate = CollectionDate;

                // Add Shipment
                String ShipmentID = AddShipmentMethod(Shipment);
                Console.WriteLine(ShipmentID);

                // Book collection
                // This is deliberatly written to handle one booking request
                String [] Bookings = new String[1];
                Bookings[0] = ShipmentID;

                ShipmentReturnType[] BookingResults = null;
                BookingResults = BookShipmentsMethod(Bookings);
                // iterate though the list of returned services
                count = 0;
                foreach (ShipmentReturnType element in BookingResults)
                {
                    count += 1;
                    System.Console.WriteLine("Service id:{0} - ShipmentID {1} - Label Url{2}", element.ServiceID, element.ShipmentID, element.LabelsURL);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
 /// <summary>
 /// Set shipment options for PMOD.
 /// </summary>
 /// <returns>this</returns>
 /// <param name="f">this</param>
 /// <param name="originEntryFacility">Origin entry facility.</param>
 /// <param name="destinationEntryFacility">Destination entry facility.</param>
 /// <param name="enclosedMailClass">Enclosed mail class.</param>
 /// <param name="enclosedParcelType">Enclosed parcel type.</param>
 /// <param name="paymentMethod">Payment method.</param>
 /// <typeparam name="T">Type of the shipment options concrete class.</typeparam>
 public static ShipmentOptionsArrayFluent <T> PMODOptions <T>(this ShipmentOptionsArrayFluent <T> f, USPSFacility originEntryFacility, USPSFacility destinationEntryFacility, Services enclosedMailClass, ParcelType enclosedParcelType, PMODPaymentMethod paymentMethod) where T : class, IShipmentOptions, new()
 {
     return(f
            .AddOption(ShipmentOption.ORIGIN_ENTRY_FACILITY, originEntryFacility.ToString())
            .AddOption(ShipmentOption.DESTINATION_ENTRY_FACILITY, destinationEntryFacility.ToString())
            .AddOption(ShipmentOption.ENCLOSED_MAIL_CLASS, enclosedMailClass.ToString())
            .AddOption(ShipmentOption.ENCLOSED_PARCEL_TYPE, enclosedParcelType.ToString())
            .AddOption(ShipmentOption.ENCLOSED_PAYMENT_METHOD, paymentMethod.ToString()));
 }
Ejemplo n.º 28
0
        public void GivenAParcelOfDefinedDimensions_WhenCreateParcel_ThenCorrectCostIsReturned(uint width, uint height,
                                                                                               uint length, decimal expectedCost, ParcelType expectedParcelType)
        {
            var parcelService = new ParcelService(Settings());
            var parcel        = parcelService.CreateParcel(width, height, length, 1);

            parcel.Type.ShouldBe(expectedParcelType);
            parcel.TotalCost.ShouldBe(expectedCost);
        }
 /// <summary>
 /// The parcel type
 /// </summary>
 /// <param name="t">Parcel type</param>
 /// <returns></returns>
 public RatesArrayFluent <T> ParcelType(ParcelType t)
 {
     _current.ParcelType = t;
     return(this);
 }
Ejemplo n.º 30
0
 public Parcel(string adress, decimal width, decimal length, decimal price, OwnerType owner, ParcelType parcelType, DateTime addedDate)
     : base(adress, width, length, price, owner, addedDate)
 {
     ParcelType = parcelType;
 }