public override async Task <SupportRequestCreateReply> Create(SupportRequestCreateRequest request, ServerCallContext context) { try { var client = TDSServer.ServiceProvider.GetRequiredService <DiscordSocketClient>(); var guild = client.GetGuild(request.GuildId); if (guild is null) { return new SupportRequestCreateReply { ErrorMessage = $"The guild with Id {request.GuildId} does not exist.", ErrorStackTrace = Environment.StackTrace, CreatedChannelId = 0, ErrorType = string.Empty } } ; var user = guild.GetUser(request.UserId); if (user is null) { return new SupportRequestCreateReply { ErrorMessage = $"The user with Id {request.UserId} does not exist.", ErrorStackTrace = Environment.StackTrace, CreatedChannelId = 0, ErrorType = string.Empty } } ; await TDSServer.ServiceProvider.GetRequiredService <SupportRequestHandler>() .CreateRequest(guild, user, request.AuthorName, request.Title, request.Text, (SupportType)request.SupportType, request.AtLeastAdminLevel, false); return(new SupportRequestCreateReply { ErrorMessage = string.Empty, ErrorStackTrace = string.Empty, CreatedChannelId = 0, ErrorType = string.Empty }); } catch (Exception ex) { var baseEx = ex.GetBaseException(); return(new SupportRequestCreateReply { ErrorMessage = baseEx.Message, ErrorStackTrace = ex.StackTrace ?? Environment.StackTrace, CreatedChannelId = 0, ErrorType = ex.GetType().Name + "|" + baseEx.GetType().Name }); } }
public HttpResponseMessage Create(SupportRequestCreateRequest model) { if (model == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Please input data to create a data request")); } if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } ItemResponse <int> generatedId = new ItemResponse <int>(); generatedId.Item = _supportRequestsService.CreateSupportRequest(model); return(Request.CreateResponse(HttpStatusCode.OK, generatedId)); }