public async Task <IActionResult> Create(ItineraryEditViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            var campaignEvent = await _mediator.SendAsync(new EventSummaryQuery { EventId = model.EventId });

            if (campaignEvent == null)
            {
                return(BadRequest());
            }

            var authorizableEvent = await _mediator.SendAsync(new AuthorizableEventQuery(campaignEvent.Id));

            if (!await authorizableEvent.UserCanEdit())
            {
                return(new ForbidResult());
            }

            var errors = _itineraryValidator.Validate(model, campaignEvent);

            errors.ToList().ForEach(e => ModelState.AddModelError(e.Key, e.Value));

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _mediator.SendAsync(new EditItineraryCommand { Itinerary = model });

            if (result > 0)
            {
                return(Ok(result));
            }

            return(BadRequest());
        }
Example #2
0
        public async Task <IActionResult> Create(ItineraryEditModel model)
        {
            if (model == null)
            {
                return(HttpBadRequest());
            }

            var campaignEvent = await _mediator.SendAsync(new EventSummaryQuery { EventId = model.EventId });

            if (campaignEvent == null)
            {
                return(HttpBadRequest());
            }

            if (!User.IsOrganizationAdmin(campaignEvent.OrganizationId))
            {
                return(HttpUnauthorized());
            }

            var errors = _itineraryValidator.Validate(model, campaignEvent);

            errors.ToList().ForEach(e => ModelState.AddModelError(e.Key, e.Value));

            if (!ModelState.IsValid)
            {
                return(HttpBadRequest(ModelState));
            }

            var result = await _mediator.SendAsync(new EditItineraryCommand()
            {
                Itinerary = model
            });

            if (result > 0)
            {
                return(Ok(result));
            }

            return(HttpBadRequest());
        }