public static MailboxNameData.Parsed Parse(this MailboxNameData target) { var modelStateDictionary = new System.Web.Http.ModelBinding.ModelStateDictionary(); MailboxName parsed0 = null; if (!MailboxName.IsEmpty(target.MailboxName)) { System.Collections.Generic.IReadOnlyCollection <string> parsed0Errors; if (!MailboxName.TryParse(target.MailboxName, out parsed0, out parsed0Errors)) { var modelState = new System.Web.Http.ModelBinding.ModelState(); foreach (var errorMessage in parsed0Errors) { modelState.Errors.Add(errorMessage); } modelStateDictionary.Add("MailboxName", modelState); } } else { var modelState = new System.Web.Http.ModelBinding.ModelState(); modelState.Errors.Add("Value required"); modelStateDictionary.Add("MailboxName", modelState); } if (!modelStateDictionary.IsValid) { throw new Fifthweek.Api.Core.ModelValidationException(modelStateDictionary); } return(new MailboxNameData.Parsed( parsed0)); }
public static NewChannelData.Parsed Parse(this NewChannelData target) { var modelStateDictionary = new System.Web.Http.ModelBinding.ModelStateDictionary(); ValidChannelName parsed0 = null; if (!ValidChannelName.IsEmpty(target.Name)) { System.Collections.Generic.IReadOnlyCollection <string> parsed0Errors; if (!ValidChannelName.TryParse(target.Name, out parsed0, out parsed0Errors)) { var modelState = new System.Web.Http.ModelBinding.ModelState(); foreach (var errorMessage in parsed0Errors) { modelState.Errors.Add(errorMessage); } modelStateDictionary.Add("Name", modelState); } } else { var modelState = new System.Web.Http.ModelBinding.ModelState(); modelState.Errors.Add("Value required"); modelStateDictionary.Add("Name", modelState); } ValidChannelPrice parsed1 = null; System.Collections.Generic.IReadOnlyCollection <string> parsed1Errors; if (!ValidChannelPrice.TryParse(target.Price, out parsed1, out parsed1Errors)) { var modelState = new System.Web.Http.ModelBinding.ModelState(); foreach (var errorMessage in parsed1Errors) { modelState.Errors.Add(errorMessage); } modelStateDictionary.Add("Price", modelState); } if (!modelStateDictionary.IsValid) { throw new Fifthweek.Api.Core.ModelValidationException(modelStateDictionary); } return(new NewChannelData.Parsed( target.BlogId, parsed0, parsed1, target.IsVisibleToNonSubscribers)); }