excellarateinc / voyage-api-dotnet

Enterprise grade C# .NET Web Services API implementing industry standard best practices
Apache License 2.0
16 stars 14 forks source link

Added Admin controller with the required status toggle change and tests #152

Closed rajeshpandalss closed 7 years ago

rajeshpandalss commented 7 years ago

Please review.

rajeshpandalss commented 7 years ago

Hi Jonathan,

Please review the committed changes.

I think throwing NotFoundException will be more apt in case the user is not found. Also, if the service fails we should be throwing Internal Server error. Your thoughts?

public async Task ToggleAccountStatus(string userId, ChangeAccountStatusModel changeAccountStatusModel) { UserModel user; if (string.IsNullOrEmpty(userId)) throw new BadRequestException(HttpStatusCode.BadRequest.ToString(), "Empty User Id."); try { user = await _userService.GetUserAsync(userId); } catch (Exception) { throw new ApiException(HttpStatusCode.InternalServerError.ToString(), "Unknown error occured. Please retry."); }

        if (user == null)
            throw new NotFoundException("User Id not found.");

        try
        {
            user.IsActive = changeAccountStatusModel.IsActive == null ? user.IsActive : (bool)changeAccountStatusModel.IsActive;
            user.IsVerifyRequired = changeAccountStatusModel.IsVerifyRequired == null ? user.IsVerifyRequired : (bool)changeAccountStatusModel.IsVerifyRequired;
            var result = await _userService.UpdateUserAsync(userId, user);
            return result;
        }
        catch (Exception)
        {
            throw new ApiException(HttpStatusCode.InternalServerError.ToString(), "Unknown error occured. Please retry.");
        }
    }