public async Task <ActionResult <SubscriptionDto> > PutSubscription(int subscriptionId, SubscriptionUpdateDto subscriptionDto) { try { var subscription = _mapper.Map <SourceSubscription>(subscriptionDto); subscription.Id = subscriptionId; var updatedSubscription = await _subscriptionService.UpdateSubscriptionAsync(subscription); var subscriptionResponse = _mapper.Map <SubscriptionDto>(updatedSubscription); return(Ok(subscriptionResponse)); } catch (SubscriptionValidationException exception) when(exception.InnerException is NotFoundSubscriptionException) { var innerMessage = GetInnerMessage(exception); return(NotFound(innerMessage)); } catch (SubscriptionValidationException exception) { var innerMessage = GetInnerMessage(exception); return(BadRequest(innerMessage)); } catch (SubscriptionServiceException exception) { return(Problem(exception.Message)); } }
public async Task <SubscriptionDto> UpdateSubscriptionAsync(SubscriptionUpdateDto subscription) { var subscriptionToUpdate = await subscriptionRepository.GetOrDefaultAsync(subscription.Id); if (subscriptionToUpdate == null) { throw new NotFoundException("No subscription found with this id"); } subscriptionToUpdate.Path = subscription.Path; var updatedSubscription = await subscriptionRepository.UpdateAsync(subscriptionToUpdate); var subscriptionDto = mapper.Map <SubscriptionDto>(updatedSubscription); return(subscriptionDto); }
public async Task ShouldUpdateSubscription() { var updatedSubscription = new SubscriptionUpdateDto { Name = "UpdatedFromTest", SourceTypeId = 1, Parameters = "{}", CreatedDate = DateTimeOffset.Now }; var httpContent = HttpUtilities.GetHttpContent(updatedSubscription); var response = await _client.PutAsync("/api/subscriptions/1", httpContent); response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); var storageSubscription = JsonConvert.DeserializeObject <SubscriptionDto>(content); storageSubscription.Should().NotBeNull(); storageSubscription.Name.Should().BeEquivalentTo(updatedSubscription.Name); }
public async Task <ActionResult <SubscriptionDto> > UpdateAsync([FromRoute] string id, [FromBody] SubscriptionUpdateDto subscription) { var updatedSubscription = await subscriptionService.UpdateSubscriptionAsync(subscription); return(Ok(updatedSubscription)); }