Exemple #1
0
        public async Task <IActionResult> UpdatePointByIdAsync(Guid pointId, PointUpdate pointToUpdate, CancellationToken ct)
        {
            if (!_accountsService.CanExecuteAdminRequest(User))
            {
                return(Unauthorized());
            }

            if (pointId == Guid.Empty)
            {
                return(BadRequest(new ApiError(Resources.InvalidParameters, Resources.IdFieldRequired)));
            }

            if (string.IsNullOrEmpty(pointToUpdate?.PointName))
            {
                return(BadRequest(new ApiError(Resources.InvalidParameters, Resources.NameFieldRequired)));
            }

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

            var point = await _pointsService.GetPointByIdAsync(pointId, ct);

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

            point = await _pointsService.UpdatePointByIdAsync(pointId, pointToUpdate.PointName, ct);

            return(Ok(point));
        }