Ejemplo n.º 1
0
        public async Task <IActionResult> Post(BrowserRestriction browserRestriction)
        {
            if (browserRestriction == null)
            {
                return(BadRequest("BrowserRestriction is required"));
            }

            using (IFeatureManagementAppTierAPI api = CreateFeatureManagementApi())
            {
                HttpOperationResponse <object> result =
                    await api.PostBrowserRestrictionWithHttpMessagesAsync(browserRestriction);

                return(CreateResponse <BrowserRestriction>(result));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Get(Guid id)
        {
            if (id == Guid.Empty)
            {
                return(BadRequest(CreateProblemDetailsResponse("Invalid Id")));
            }

            BrowserRestriction browserRestriction = await _browserRestrictionService
                                                    .GetByIdAsync(id)
                                                    .ConfigureAwait(false);

            return(browserRestriction == null
                ? (IActionResult)NotFound()
                : Ok(browserRestriction));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Put(Guid id, BrowserRestriction browserRestriction)
        {
            if (id == Guid.Empty)
            {
                return(BadRequest(CreateProblemDetailsResponse("Invalid Id")));
            }

            if (browserRestriction == null)
            {
                return(BadRequest(CreateProblemDetailsResponse("BrowserRestriction is required")));
            }

            BrowserRestriction existingBrowserRestriction = await _browserRestrictionService
                                                            .GetByIdAsync(id)
                                                            .ConfigureAwait(false);

            if (existingBrowserRestriction == null)
            {
                return(NotFound());
            }

            if (existingBrowserRestriction.Id != browserRestriction.Id)
            {
                return(BadRequest(CreateProblemDetailsResponse("BrowserRestriction Id mismatch")));
            }

            Feature feature = await _featureService
                              .GetByIdAsync(browserRestriction.FeatureId)
                              .ConfigureAwait(false);

            if (feature == null)
            {
                return(BadRequest(CreateProblemDetailsResponse("Feature not found")));
            }

            browserRestriction.ModifiedOn = DateTimeOffset.Now;
            BrowserRestriction updatedBrowserRestriction = _browserRestrictionService.Update(browserRestriction);

            return(updatedBrowserRestriction == null
                ? (IActionResult)StatusCode(StatusCodes.Status500InternalServerError)
                : Ok(updatedBrowserRestriction));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Delete(Guid id)
        {
            if (id == Guid.Empty)
            {
                return(BadRequest(CreateProblemDetailsResponse("Invalid Id")));
            }

            BrowserRestriction existingBrowserRestriction = await _browserRestrictionService.GetByIdAsync(id)
                                                            .ConfigureAwait(false);

            if (existingBrowserRestriction == null)
            {
                return(NotFound());
            }

            _browserRestrictionService.DeleteById(id);
            BrowserRestriction browserRestriction = await _browserRestrictionService.GetByIdAsync(id);

            return(browserRestriction == null
                ? StatusCode(StatusCodes.Status500InternalServerError)
                : Ok());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Post(BrowserRestriction browserRestriction,
                                               CancellationToken cancellationToken = default)
        {
            if (browserRestriction == null)
            {
                return(BadRequest(CreateProblemDetailsResponse("BrowserRestriction is required")));
            }

            Feature feature = await _featureService
                              .GetByIdAsync(browserRestriction.FeatureId)
                              .ConfigureAwait(false);

            if (feature == null)
            {
                return(BadRequest(CreateProblemDetailsResponse("Feature not found")));
            }

            List <BrowserRestriction> featureBrowserRestrictions = await _browserRestrictionService
                                                                   .GetByFeatureId(browserRestriction.FeatureId, cancellationToken).ConfigureAwait(false);

            if (featureBrowserRestrictions.Any(f => f.SupportedBrowserId == browserRestriction.SupportedBrowserId))
            {
                ProblemDetails problemDetailsResponse = CreateProblemDetailsResponse(
                    $"Feature already has a browser restriction for {browserRestriction.SupportedBrowserId.ToString()}");
                return(BadRequest(problemDetailsResponse));
            }

            browserRestriction.CreatedOn = DateTimeOffset.Now;
            BrowserRestriction newBrowserRestriction = await _browserRestrictionService
                                                       .AddAsync(browserRestriction)
                                                       .ConfigureAwait(false);

            return(newBrowserRestriction == null
                ? (IActionResult)StatusCode(StatusCodes.Status500InternalServerError)
                : Ok(newBrowserRestriction));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Update a Browser Restriction
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='id'>
 /// </param>
 /// <param name='body'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <object> PutBrowserRestrictionAsync(this IFeatureManagementAppTierAPI operations, System.Guid id, BrowserRestriction body = default(BrowserRestriction), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.PutBrowserRestrictionWithHttpMessagesAsync(id, body, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }