public static UpdatedChannelData.Parsed Parse(this UpdatedChannelData 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 UpdatedChannelData.Parsed(
                       parsed0,
                       parsed1,
                       target.IsVisibleToNonSubscribers));
        }
        protected bool Equals(UpdatedChannelData other)
        {
            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);
        }
Пример #3
0
        public async Task <IHttpActionResult> PutChannelAsync(string channelId, [FromBody] UpdatedChannelData channelData)
        {
            channelId.AssertUrlParameterProvided("channelId");
            channelData.AssertBodyProvided("channelData");
            var channel = channelData.Parse();

            var requester = await this.requesterContext.GetRequesterAsync();

            var channelIdObject = new ChannelId(channelId.DecodeGuid());

            await this.updateChannel.HandleAsync(
                new UpdateChannelCommand(
                    requester,
                    channelIdObject,
                    channel.Name,
                    channel.Price,
                    channel.IsVisibleToNonSubscribers));

            return(this.Ok());
        }