コード例 #1
0
ファイル: FulfillmentDetails.cs プロジェクト: toddca/sdk_net
        public void Validate(Validations validationType = Validations.Weak)
        {
            InputValidators.ValidateValuedString(FulfillmentId, "Fulfillment Id");
            InputValidators.ValidateDateNotDefault(CreatedAt.GetValueOrDefault(), "Created At");
            InputValidators.ValidateObjectNotNull(Status, "Status");


            LineItems?.ToList().ForEach(item => item.Validate(validationType));
        }
コード例 #2
0
        /// <summary>
        /// Converts this <see cref="TimeEntryModel"/> to a <see cref="TimeEntry"/>
        /// </summary>
        /// <returns>
        /// A <see cref="TimeEntry"/> object representing this instance of a <see cref="TimeEntryModel"/> object
        /// </returns>
        public TimeEntry ToEntity()
        {
            var entity = new TimeEntry
            {
                TimeEntryId = TimeEntryId,
                ProjectId   = ProjectId,
                UserId      = UserId,
                FromTime    = FromTime.HasValue ? DateTime.Parse(DateWorked.ToShortDateString() + " " + FromTime.Value.ToShortTimeString()) : null as DateTime?,
                ToTime      = ToTime.HasValue ? DateTime.Parse(DateWorked.ToShortDateString() + " " + ToTime.Value.ToShortTimeString()) : null as DateTime?,
                TotalTime   = TotalTime,
                DateWorked  = DateWorked,
                IsBillable  = IsBillable,
                CreatedAt   = CreatedAt.GetValueOrDefault(),
                CreatedBy   = CreatedBy,
                Description = Description
            };

            return(entity);
        }
コード例 #3
0
        /// <summary>
        ///     Validates the objects fields content
        /// </summary>
        /// <param name="validationType"></param>
        /// <exception cref="OrderFieldBadFormatException">
        ///     throws an exception if one of the parameters doesn't match the expected
        ///     format
        /// </exception>
        public override void Validate(Validations validationType = Validations.Weak)
        {
            base.Validate(validationType);
            InputValidators.ValidateObjectNotNull(LineItems, "Line Items");
            LineItems.ToList().ForEach(item => item.Validate(validationType));
            InputValidators.ValidateObjectNotNull(ShippingLines, "Shipping Lines");
            ShippingLines.ToList().ForEach(item => item.Validate(validationType));
            if (PaymentDetails == null && NoChargeAmount == null)
            {
                throw new OrderFieldBadFormatException("Both PaymentDetails and NoChargeDetails are missing - at least one should be specified");
            }
            if (PaymentDetails != null && PaymentDetails.Length > 0)
            {
                PaymentDetails.ToList().ForEach(item => item.Validate(validationType));
            }
            else
            {
                NoChargeAmount.Validate(validationType);
            }

            if (validationType == Validations.Weak)
            {
                if (BillingAddress == null && ShippingAddress == null)
                {
                    throw new OrderFieldBadFormatException("Both shipping and billing addresses are missing - at least one should be specified");
                }

                if (BillingAddress != null)
                {
                    BillingAddress.Validate(validationType);
                }
                else
                {
                    ShippingAddress.Validate(validationType);
                }

                if (CustomerBrowserIp != null)
                {
                    InputValidators.ValidateIp(CustomerBrowserIp);
                }
            }
            else
            {
                InputValidators.ValidateObjectNotNull(BillingAddress, "Billing Address");
                BillingAddress.Validate(validationType);
                InputValidators.ValidateObjectNotNull(ShippingAddress, "Shipping Address");
                ShippingAddress.Validate(validationType);
                InputValidators.ValidateIp(CustomerBrowserIp);
            }

            InputValidators.ValidateObjectNotNull(Customer, "Customer");
            Customer.Validate(validationType);
            InputValidators.ValidateEmail(Email);
            InputValidators.ValidateCurrency(Currency);
            InputValidators.ValidateZeroOrPositiveValue(TotalPrice.GetValueOrDefault(), "Total Price");
            InputValidators.ValidateValuedString(Gateway, "Gateway");
            InputValidators.ValidateDateNotDefault(CreatedAt.GetValueOrDefault(), "Created At");
            InputValidators.ValidateDateNotDefault(UpdatedAt.GetValueOrDefault(), "Updated At");

            // optional fields validations
            if (DiscountCodes != null && DiscountCodes.Length > 0)
            {
                DiscountCodes.ToList().ForEach(item => item.Validate(validationType));
            }
            if (TotalPriceUsd.HasValue)
            {
                InputValidators.ValidateZeroOrPositiveValue(TotalPriceUsd.Value, "Total Price USD");
            }
            if (TotalDiscounts.HasValue)
            {
                InputValidators.ValidateZeroOrPositiveValue(TotalDiscounts.Value, "Total Discounts");
            }
            if (ClosedAt.HasValue)
            {
                InputValidators.ValidateDateNotDefault(ClosedAt.Value, "Closed At");
            }
        }