예제 #1
0
        public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
        {
            if (bindingContext.ModelType != typeof(QuotationParameter))
            {
                return(false);
            }

            ValueProviderResult value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);

            if (value == null)
            {
                return(false);
            }

            string key = value.RawValue as string;

            if (key == null)
            {
                bindingContext.ModelState.AddModelError(bindingContext.ModelName, "Wrong value type");
                return(false);
            }

            var parameter = QuotationParameter.Parse(key);

            if (parameter != null)
            {
                bindingContext.Model = parameter;
                return(true);
            }

            bindingContext.ModelState.AddModelError(
                bindingContext.ModelName, "Cannot convert value to Quotation Parameters");
            return(false);
        }
        public static QuotationParameter Parse(string entryParameters)
        {
            var parameterParts           = entryParameters.Split(',');
            int countOfCurrentParameters = typeof(QuotationParameter).GetProperties().Length;

            if (parameterParts.Length == 0 || parameterParts.Length < countOfCurrentParameters)
            {
                return(null);
            }

            QuotationParameter result = new QuotationParameter
            {
                QuotationId        = parameterParts[0].ToStringValueOrEmpty(),
                QuotationStatusId  = parameterParts[1].ToStringValueOrEmpty(),
                CustomerId         = parameterParts[2].ToStringValueOrEmpty(),
                QuotationEntryDate = parameterParts[3].ToStringValueOrEmpty(),
                LookupType         = parameterParts[4].ToStringValueOrEmpty()
            };

            return(result);
        }