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)); }
public async Task <ChannelId> PostChannelAsync(NewChannelData newChannelData) { newChannelData.AssertBodyProvided("newChannel"); var newChannel = newChannelData.Parse(); var requester = await this.requesterContext.GetRequesterAsync(); var newChannelId = new ChannelId(this.guidCreator.CreateSqlSequential()); await this.createChannel.HandleAsync( new CreateChannelCommand( requester, newChannelId, newChannel.BlogId, newChannel.Name, newChannel.Price, newChannel.IsVisibleToNonSubscribers)); return(newChannelId); }
protected bool Equals(NewChannelData other) { if (!object.Equals(this.BlogId, other.BlogId)) { return(false); } if (!object.Equals(this.Name, other.Name)) { return(false); } if (!object.Equals(this.Price, other.Price)) { return(false); } if (!object.Equals(this.IsVisibleToNonSubscribers, other.IsVisibleToNonSubscribers)) { return(false); } return(true); }