This commit is contained in:
mmrbnjd
2025-08-16 01:46:25 +03:30
parent 86804a57f1
commit bd1f907673
4 changed files with 163 additions and 5 deletions

View File

@@ -0,0 +1,97 @@
@page "/prompt"
@using Common.Dtos.Prompt
@using HushianWebApp.Service
@inject PromptService promptService
<div class="row" style="height: fit-content; padding: 1rem;">
<div class="col-md-12">
<TextAreaInput dir="rtl" style="text-align:right;margin-bottom:10px" @bind-value="@newPrompt.Test" class="form-control" placeholder="متن پرامپت"></TextAreaInput>
</div>
<div class="col-md-12" style="margin-bottom:10px;">
<Button Color="ButtonColor.Success" @onclick="AddPrompt">ثبت</Button>
</div>
<div class="col-md-12">
@if (loading)
{
<p>در حال بارگذاری...</p>
}
else if (prompts == null || prompts.Count == 0)
{
<p>موردی یافت نشد</p>
}
else
{
<table class="table table-striped">
<thead>
<tr>
<th>متن</th>
<th style="width:110px">عملیات</th>
</tr>
</thead>
<tbody>
@foreach (var p in prompts)
{
<tr>
<td>
<TextAreaInput class="form-control" @bind-value="p.Test"></TextAreaInput>
</td>
<td>
<Button Color="ButtonColor.Warning" class="me-1" @onclick="(()=>UpdatePrompt(p))"><Icon Name="IconName.CloudLightning" /></Button>
<Button Color="ButtonColor.Danger" @onclick="(()=>DeletePrompt(p.ID))"><Icon Name="IconName.Trash" /></Button>
</td>
</tr>
}
</tbody>
</table>
}
</div>
</div>
@code {
private List<ReadANDUpdate_PromptDto> prompts = new();
private ADD_PromptDto newPrompt = new();
private bool loading = false;
}
@functions {
protected override async Task OnInitializedAsync()
{
await LoadPrompts();
}
private async Task LoadPrompts()
{
loading = true;
prompts = await promptService.GetPrompts();
loading = false;
}
private async Task AddPrompt()
{
if (!string.IsNullOrWhiteSpace(newPrompt.Test))
{
if (await promptService.AddPrompt(newPrompt))
{
newPrompt = new();
await LoadPrompts();
}
}
}
private async Task UpdatePrompt(ReadANDUpdate_PromptDto model)
{
if (!string.IsNullOrWhiteSpace(model.Test))
{
if (await promptService.UpdatePrompt(model))
{
await LoadPrompts();
}
}
}
private async Task DeletePrompt(int id)
{
if (await promptService.DeletePrompt(id))
{
await LoadPrompts();
}
}
}

View File

@@ -110,16 +110,20 @@
<!-- محتوای دلخواه -->
</div>
</div>
<!-- پایین راست -->
*@
@if (ALLOWcompanyinfo)
{
<!-- پایین راست -->
<div class="col-md-6 d-flex flex-column">
<div class="section-box w-100">
<div class="section-title">
<i class="bi bi-chat-dots-fill"></i> بخش پایین راست
<i class="bi bi-chat-dots-fill"></i> درباره مجموعه:
</div>
<!-- محتوای دلخواه -->
<PromptManagerComponent />
</div>
</div> *@
</div>
}
</div>
</div>

View File

@@ -16,6 +16,7 @@ builder.Services.AddScoped<VerificationService>();
builder.Services.AddScoped<UserService>();
builder.Services.AddScoped<CompanyService>();
builder.Services.AddScoped<GroupService>();
builder.Services.AddScoped<PromptService>();
builder.Services.AddScoped<ConversationService>();
builder.Services.AddScoped<ChatService>();
builder.Services.AddBlazorBootstrap();

View File

@@ -0,0 +1,56 @@
using Common.Dtos.Prompt;
using System.Net.Http.Json;
namespace HushianWebApp.Service
{
public class PromptService
{
private readonly BaseController _baseController;
const string BaseRoute = "v1/Prompt/";
public PromptService(BaseController baseController)
{
_baseController = baseController;
}
public async Task<bool> AddPrompt(ADD_PromptDto model)
{
var response = await _baseController.Post($"{BaseRoute}AddPrompt", model);
return response.IsSuccessStatusCode;
}
public async Task<bool> UpdatePrompt(ReadANDUpdate_PromptDto model)
{
var response = await _baseController.Put($"{BaseRoute}UpdatePrompt", model);
return response.IsSuccessStatusCode;
}
public async Task<bool> DeletePrompt(int id)
{
var response = await _baseController.Delete($"{BaseRoute}DeletePrompt/{id}");
return response.IsSuccessStatusCode;
}
public async Task<ReadANDUpdate_PromptDto?> GetPrompt(int id)
{
var response = await _baseController.Get($"{BaseRoute}GetPrompt/{id}");
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadFromJsonAsync<ReadANDUpdate_PromptDto>();
}
return null;
}
public async Task<List<ReadANDUpdate_PromptDto>> GetPrompts()
{
var response = await _baseController.Get($"{BaseRoute}GetPrompts");
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadFromJsonAsync<List<ReadANDUpdate_PromptDto>>() ?? new();
}
return new();
}
}
}