public async Task <IActionResult> HandleRequest([FromBody] HandleRequestModel model) { // request should be unhandled var requestId = XUtils.ParseId(model.RequestId); var request = await Context.AdminRequests.FirstOrDefaultAsync(p => p.Id == requestId); if (request == null) { return(new ApiError(MyErrorCode.IdNotFound, "Request id not found").Wrap()); } if (request.Status != RequestStatus.Unhandled) { return(new ApiError(MyErrorCode.TypeMismatch, "Request is not unhandled").Wrap()); } // should have super role var member = await Context.TopicMembers .FirstOrDefaultAsync(p => p.UserId == AuthStore.UserId && p.TopicId == request.TopicId); if (member.Role != MemberRole.Super) { return(new ApiError(MyErrorCode.PermissionDenied, "You are not super administrator of the group").Wrap()); } // handle request.Handle(model.Accept); if (model.Accept) { var membership2 = await Context.TopicMembers .FirstOrDefaultAsync(p => p.UserId == request.SenderId && p.TopicId == request.TopicId); membership2.SetRole(MemberRole.Admin); } await Context.GoAsync(); return(Ok()); }
/// <summary> /// /// </summary> /// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="handleRequestModel"> (optional)</param> /// <returns>Task of ApiResponse</returns> public async System.Threading.Tasks.Task <Org.OpenAPITools.Client.ApiResponse <Object> > HandleRequestAsyncWithHttpInfo(HandleRequestModel handleRequestModel = default(HandleRequestModel)) { Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); String[] _contentTypes = new String[] { "application/json" }; // to determine the Accept header String[] _accepts = new String[] { }; foreach (var _contentType in _contentTypes) { localVarRequestOptions.HeaderParameters.Add("Content-Type", _contentType); } foreach (var _accept in _accepts) { localVarRequestOptions.HeaderParameters.Add("Accept", _accept); } localVarRequestOptions.Data = handleRequestModel; // make the HTTP request var localVarResponse = await this.AsynchronousClient.PostAsync <Object>("/api/group-management/handle-request", localVarRequestOptions, this.Configuration); if (this.ExceptionFactory != null) { Exception _exception = this.ExceptionFactory("HandleRequest", localVarResponse); if (_exception != null) { throw _exception; } } return(localVarResponse); }
/// <summary> /// /// </summary> /// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="handleRequestModel"> (optional)</param> /// <returns>ApiResponse of Object(void)</returns> public Org.OpenAPITools.Client.ApiResponse <Object> HandleRequestWithHttpInfo(HandleRequestModel handleRequestModel = default(HandleRequestModel)) { Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions(); String[] _contentTypes = new String[] { "application/json" }; // to determine the Accept header String[] _accepts = new String[] { }; var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes); if (localVarContentType != null) { localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); } var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts); if (localVarAccept != null) { localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); } localVarRequestOptions.Data = handleRequestModel; // make the HTTP request var localVarResponse = this.Client.Post <Object>("/api/group-management/handle-request", localVarRequestOptions, this.Configuration); if (this.ExceptionFactory != null) { Exception _exception = this.ExceptionFactory("HandleRequest", localVarResponse); if (_exception != null) { throw _exception; } } return(localVarResponse); }
/// <summary> /// /// </summary> /// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="handleRequestModel"> (optional)</param> /// <returns>Task of void</returns> public async System.Threading.Tasks.Task HandleRequestAsync(HandleRequestModel handleRequestModel = default(HandleRequestModel)) { await HandleRequestAsyncWithHttpInfo(handleRequestModel); }
/// <summary> /// /// </summary> /// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="handleRequestModel"> (optional)</param> /// <returns></returns> public void HandleRequest(HandleRequestModel handleRequestModel = default(HandleRequestModel)) { HandleRequestWithHttpInfo(handleRequestModel); }