Пример #1
0
        public async Task <IActionResult> Active([Required, FromRoute] Guid id, [Required, FromQuery] bool active)
        {
            try
            {
                bool success = await repository.ChangeStatusAsync(new ActiveStatus
                {
                    Id     = id,
                    Active = active
                });

                if (success)
                {
                    return(Ok(DataResponse.Succeeded("Status changed successfully")));
                }
                return(NotFound(DataResponse.Failure($"Org id '{id}' not found")));
            }
            catch (Exception ex)
            {
                if (ex is BadRequestException || ex is ArgumentNullException || ex is ArgumentException)
                {
                    return(BadRequest(DataResponse.Failure("Invalid org id")));
                }
                else if (ex is NotFoundException)
                {
                    return(NotFound(DataResponse.Failure("Organization not found")));
                }
                else
                {
                    //return StatusCode(StatusCodes.Status500InternalServerError, DataResponse.Failure(ex.Message));
                    return(InternalServerError(DataResponse.Failure(ex.Message)));
                }
            }
        }