...
This commit is contained in:
15
Common/Dtos/Prompt/ADD_PromptDto.cs
Normal file
15
Common/Dtos/Prompt/ADD_PromptDto.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Common.Dtos.Prompt
|
||||
{
|
||||
public class ADD_PromptDto
|
||||
{
|
||||
public string Test { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
18
Common/Dtos/Prompt/ReadANDUpdate_PromptDto.cs
Normal file
18
Common/Dtos/Prompt/ReadANDUpdate_PromptDto.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Common.Dtos.Prompt
|
||||
{
|
||||
public class ReadANDUpdate_PromptDto
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public DateTime Cdatetime { get; set; }
|
||||
public int CompanyID { get; set; }
|
||||
public string Test { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -66,6 +66,7 @@ namespace Hushian.Application
|
||||
services.AddScoped(typeof(ChatService));
|
||||
services.AddScoped(typeof(ExperService));
|
||||
services.AddScoped(typeof(GroupService));
|
||||
services.AddScoped(typeof(PromptService));
|
||||
services.AddScoped(typeof(UserService));
|
||||
services.AddScoped(typeof(VerificationService));
|
||||
services.Configure<JwtSettings>(configuration.GetSection("JwtSettings"));
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using Common.Dtos.Company;
|
||||
using Common.Dtos.Exper;
|
||||
using Common.Dtos.Group;
|
||||
using Common.Dtos.Prompt;
|
||||
using Hushian.Domain.Entites;
|
||||
|
||||
|
||||
@@ -17,6 +18,8 @@ namespace Hushian.Application
|
||||
CreateMap<Exper, Read_ExperDto>().ReverseMap();
|
||||
CreateMap<ADD_GroupDto, Group>();
|
||||
CreateMap<Group, Read_GroupDto>();
|
||||
CreateMap<ADD_PromptDto, Prompt>();
|
||||
CreateMap<Prompt, ReadANDUpdate_PromptDto>().ReverseMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
93
Hushian.Application/Services/PromptService.cs
Normal file
93
Hushian.Application/Services/PromptService.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using AutoMapper;
|
||||
using Common.Dtos.Prompt;
|
||||
using Hushian.Application.Contracts.Persistence;
|
||||
using Hushian.Application.Models;
|
||||
using Hushian.Domain.Entites;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Hushian.Application.Services
|
||||
{
|
||||
public class PromptService
|
||||
{
|
||||
private readonly IGenericRepository<Prompt> _promptRepository;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public PromptService(IGenericRepository<Prompt> promptRepository, IMapper mapper)
|
||||
{
|
||||
_promptRepository = promptRepository;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<ResponseBase<bool>> AddPrompt(ADD_PromptDto model, int CompanyID)
|
||||
{
|
||||
ResponseBase<bool> response = new();
|
||||
try
|
||||
{
|
||||
var entity = _mapper.Map<Prompt>(model);
|
||||
entity.CompanyID = CompanyID;
|
||||
entity.Cdatetime = DateTime.Now;
|
||||
response.Value = response.Success = await _promptRepository.ADDBool(entity);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
response.Errors.Add("خطا در ذخیره سازی");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<ReadANDUpdate_PromptDto?> GetPrompt(int id, int CompanyID)
|
||||
{
|
||||
var entity = await _promptRepository.Get().FirstOrDefaultAsync(f => f.ID == id && f.CompanyID == CompanyID);
|
||||
return _mapper.Map<ReadANDUpdate_PromptDto>(entity);
|
||||
}
|
||||
|
||||
public async Task<List<ReadANDUpdate_PromptDto>> GetCompanyPrompts(int CompanyID)
|
||||
{
|
||||
var list = await _promptRepository.Get().Where(w => w.CompanyID == CompanyID).OrderByDescending(o=>o.ID).ToListAsync();
|
||||
return _mapper.Map<List<ReadANDUpdate_PromptDto>>(list);
|
||||
}
|
||||
|
||||
public async Task<ResponseBase<bool>> UpdatePrompt(ReadANDUpdate_PromptDto model, int CompanyID)
|
||||
{
|
||||
ResponseBase<bool> response = new();
|
||||
try
|
||||
{
|
||||
var entity = await _promptRepository.Get().FirstOrDefaultAsync(f => f.ID == model.ID && f.CompanyID == CompanyID);
|
||||
if (entity == null)
|
||||
{
|
||||
response.Errors.Add("یافت نشد");
|
||||
return response;
|
||||
}
|
||||
entity.Test = model.Test;
|
||||
response.Value = response.Success = await _promptRepository.UPDATEBool(entity);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
response.Errors.Add("خطای سیستمی");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<ResponseBase<bool>> DeletePrompt(int id, int CompanyID)
|
||||
{
|
||||
ResponseBase<bool> response = new();
|
||||
try
|
||||
{
|
||||
var entity = await _promptRepository.Get().FirstOrDefaultAsync(f => f.ID == id && f.CompanyID == CompanyID);
|
||||
if (entity == null)
|
||||
{
|
||||
response.Errors.Add("یافت نشد");
|
||||
return response;
|
||||
}
|
||||
response.Value = response.Success = await _promptRepository.DELETE(entity);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
response.Errors.Add("خطای سیستمی");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,74 @@
|
||||
using Common.Dtos.Prompt;
|
||||
using Hushian.Application.Constants;
|
||||
using Hushian.Application.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Hushian.WebApi.Controllers.v1
|
||||
{
|
||||
[Route("api/v1/[controller]")]
|
||||
[ApiController]
|
||||
public class PromptController : ControllerBase
|
||||
{
|
||||
private readonly PromptService _promptService;
|
||||
public PromptController(PromptService promptService)
|
||||
{
|
||||
_promptService = promptService;
|
||||
}
|
||||
|
||||
[HttpPost("AddPrompt")]
|
||||
[Authorize(Roles = "Company")]
|
||||
public async Task<ActionResult> AddPrompt([FromBody] ADD_PromptDto model)
|
||||
{
|
||||
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int CompanyID = Convert.ToInt32(strCompanyID);
|
||||
var response = await _promptService.AddPrompt(model, CompanyID);
|
||||
return response.Success && response.Value ? NoContent()
|
||||
: BadRequest(response.Errors);
|
||||
}
|
||||
|
||||
[HttpPut("UpdatePrompt")]
|
||||
[Authorize(Roles = "Company")]
|
||||
public async Task<ActionResult> UpdatePrompt([FromBody] ReadANDUpdate_PromptDto model)
|
||||
{
|
||||
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int CompanyID = Convert.ToInt32(strCompanyID);
|
||||
var response = await _promptService.UpdatePrompt(model, CompanyID);
|
||||
return response.Success && response.Value ? NoContent()
|
||||
: BadRequest(response.Errors);
|
||||
}
|
||||
|
||||
[HttpDelete("DeletePrompt/{id}")]
|
||||
[Authorize(Roles = "Company")]
|
||||
public async Task<ActionResult> DeletePrompt(int id)
|
||||
{
|
||||
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int CompanyID = Convert.ToInt32(strCompanyID);
|
||||
var response = await _promptService.DeletePrompt(id, CompanyID);
|
||||
return response.Success && response.Value ? NoContent()
|
||||
: BadRequest(response.Errors);
|
||||
}
|
||||
|
||||
[HttpGet("GetPrompt/{id}")]
|
||||
[Authorize(Roles = "Company")]
|
||||
public async Task<ActionResult<ReadANDUpdate_PromptDto>> GetPrompt(int id)
|
||||
{
|
||||
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int CompanyID = Convert.ToInt32(strCompanyID);
|
||||
var response = await _promptService.GetPrompt(id, CompanyID);
|
||||
return response != null ? Ok(response) : NotFound();
|
||||
}
|
||||
|
||||
[HttpGet("GetPrompts")]
|
||||
[Authorize(Roles = "Company")]
|
||||
public async Task<ActionResult<List<ReadANDUpdate_PromptDto>>> GetPrompts()
|
||||
{
|
||||
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
||||
int CompanyID = Convert.ToInt32(strCompanyID);
|
||||
var response = await _promptService.GetCompanyPrompts(CompanyID);
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user