serv full ticket

This commit is contained in:
mmrbnjd
2024-05-01 15:42:21 +03:30
parent 827aa36860
commit 720b2f00ce
23 changed files with 353 additions and 58 deletions

View File

@@ -6,6 +6,13 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Common\DTOs\**" />
<Content Remove="Common\DTOs\**" />
<EmbeddedResource Remove="Common\DTOs\**" />
<None Remove="Common\DTOs\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Melipayamak.RestClient" Version="1.0.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" />
@@ -24,10 +31,6 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Common\DTOs\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>

View File

@@ -1,4 +1,4 @@
using Back.Common.Enums;
using Shared.DTOs;
using Back.Data.Models;
using Back.Services;
using Back.Validations;
@@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc;
using Shared.DTOs;
using System.Security.Cryptography;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
using Shared.DTOs.Serch;
namespace Back.Controllers
{
@@ -21,32 +22,97 @@ namespace Back.Controllers
private readonly servTicket _servTicket;
private readonly ServValidatinMsg _servValidatinMsg;
private readonly servSendMsg _servSendMsg;
private readonly servCompany _servCompany;
private readonly servUser _servUser;
public TicketController(MobileValidation mobilevalidation, servTicket servTicket
, ServValidatinMsg servValidatinMsg, servSendMsg servSendMsg)
, ServValidatinMsg servValidatinMsg, servSendMsg servSendMsg
, servCompany servCompany, servUser servUser)
{
_mobilevalidation = mobilevalidation;
_servTicket = servTicket;
_servValidatinMsg = servValidatinMsg;
_servSendMsg = servSendMsg;
_servUser = servUser;
_servCompany = servCompany;
}
[HttpPost("GetAll")]
public async Task<ActionResult<PagingDto<TicketDTO>>> GetAll(ItemSerchGetTicket itemSerch)
{
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
return Ok(await _servTicket.GetAll(user.RolUsers.First().CompanyID, itemSerch));
}
[HttpGet("GetSubTicket/{TicketID}")]
public async Task<ActionResult<ICollection<SubTicketDTO>>> GetSubTicket(int TicketID)
{
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
return Ok(await _servTicket.GetSubTicket(user.RolUsers.First().CompanyID, TicketID));
}
[HttpPost("NewTicket")]
public async Task<ActionResult<int>> NewTicket(CTicketDto item)
{
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
item.CompanyID = user.RolUsers.First().CompanyID.ToString();
var res = await _servTicket.NewTicket(item);
return Ok(res != null);
}
[HttpPost("AddSubicket")]
public async Task<ActionResult<int>> AddSubicket(AddSubTicket item)
{
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
var Ticket = await _servTicket.GetTicketorgbyTicketID(user.RolUsers.First().CompanyID,item.TicketID);
if (Ticket==null)
return NotFound(new List<string>() { "تیکت یافت نشد" });
if (!string.IsNullOrEmpty(Ticket.EndDate)) return BadRequest(new List<string>() { "این تیکت بسته شده" });
var subTicket = await _servTicket.AddSubTicket(item);
Ticket.Status = StatusTicket.Awaitingreview;
await _servTicket.UpdateTicket(Ticket);
return Ok(subTicket);
}
[HttpPut("CancelTicket/{TicketID}")]
public async Task<ActionResult<bool>> CancelTicket(int TicketID)
{
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
var Ticket = await _servTicket.GetTicketorgbyTicketID(user.RolUsers.First().CompanyID,TicketID);
if (Ticket == null)
return NotFound(new List<string>() { "تیکت یافت نشد" });
if (!string.IsNullOrEmpty(Ticket.EndDate)) return BadRequest("این تیکت قبلا بسته شده");
Ticket.Status = StatusTicket.optout;
return Ok(await _servTicket.UpdateTicket(Ticket));
}
[HttpPost("NewTicketNoAuthentication")]
[AllowAnonymous]
public async Task<ActionResult<int>> NewTicketNoAuthentication(CTicketNoAuthenticationDto item)
{
var resultValidationmodel = await _mobilevalidation.ValidateAsync(Tuple.Create(item.Mobile,ActionMobileValidation.No));
var resultValidationmodel = await _mobilevalidation.ValidateAsync(Tuple.Create(item.Mobile, ActionMobileValidation.No));
if (!resultValidationmodel.IsValid)
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
var pid=await _servTicket.NewPepole(item.FullName,item.Mobile);
var pid = await _servTicket.NewPepole(item.FullName, item.Mobile);
item.CompanyID = pid.Value.ToString();
var Ticket = await _servTicket.NewTicket(item, StatusTicket.unknownPerson);
var ID= await _servValidatinMsg.GenerateCode(new VerificationCode
var ID = await _servValidatinMsg.GenerateCode(new VerificationCode
{
prm = Ticket.ID.ToString(),
val = item.Mobile,
Type = "NewTicketNoAuthentication"
Type = "NewTicketNoAuthentication"
});
_servSendMsg.Authentication(item.Mobile, ID.ToString());
return Ticket == null ? BadRequest() : Ok(ID);

View File

@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Back.Common.Enums;
using Shared.DTOs;
namespace Back.Data.Models
{

View File

@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Back.Common;
using Back.Common.Enums;
using Shared.DTOs;
namespace Back.Data.Models
{
public class Invoice

View File

@@ -1,5 +1,5 @@
using System.ComponentModel.DataAnnotations.Schema;
using Back.Common.Enums;
using Shared.DTOs;
using System.ComponentModel.DataAnnotations.Schema;
namespace Back.Data.Models
{

View File

@@ -1,5 +1,5 @@
using System.ComponentModel.DataAnnotations.Schema;
using Back.Common.Enums;
using Shared.DTOs;
namespace Back.Data.Models
{
public class SentTax

View File

@@ -1,5 +1,5 @@
using System.ComponentModel.DataAnnotations.Schema;
using Back.Common.Enums;
using Shared.DTOs;
namespace Back.Data.Models
{

View File

@@ -1,5 +1,5 @@
using System.ComponentModel.DataAnnotations;
using Back.Common.Enums;
using Shared.DTOs;
namespace Back.Data.Models
{

View File

@@ -1,4 +1,4 @@
using Back.Common.Enums;
using Shared.DTOs;
using Back.Data.Contracts;
using Back.Data.Models;
using Microsoft.EntityFrameworkCore;

View File

@@ -1,4 +1,4 @@
using Back.Common.Enums;
using Shared.DTOs;
using Back.Data.Contracts;
using Back.Data.Models;
using Microsoft.EntityFrameworkCore;

View File

@@ -1,18 +1,21 @@
using Back.Common;
using Back.Common.Enums;
using Shared.DTOs;
using Back.Data.Contracts;
using Back.Data.Models;
using Shared.DTOs;
using Shared.DTOs.Serch;
using Microsoft.EntityFrameworkCore;
using Back.Data.Infrastructure.Repository;
using System.Net.Sockets;
namespace Back.Services
{
public class servTicket
{
private readonly IAsyncRepository<TiceketUnknownPeople> _ticketUnknownPeopleRepo;
private readonly IAsyncRepository<Ticket> _ticketRepo;
private readonly RepositoryBase<Ticket> _ticketRepo;
private readonly IAsyncRepository<SubTicket> _subticketRepo;
public servTicket(IAsyncRepository<TiceketUnknownPeople> ticketUnknownPeopleRepo
,IAsyncRepository<Ticket> ticketRepo
, RepositoryBase<Ticket> ticketRepo
,IAsyncRepository<SubTicket> subticketRepo
)
{
@@ -20,14 +23,134 @@ namespace Back.Services
_ticketRepo = ticketRepo;
_subticketRepo = subticketRepo;
}
public async Task<PagingDto<TicketDTO>> GetAll(int CompanyID, ItemSerchGetTicket itemSerch)
{
#region AdvancedSearch
var invok = _ticketRepo
.Get(w => w.CompanyIDOrMobile == CompanyID.ToString());
if (!string.IsNullOrEmpty(itemSerch.Title))
invok = invok.Where(w => w.Title.Contains(itemSerch.Title));
if (itemSerch.TicketID.HasValue)
invok = invok.Where(w => w.ID == itemSerch.TicketID);
#endregion
//-----------------------
return await invok.OrderByDescending(o => o.ID)
.Select(s => new TicketDTO()
{
CreateDate = s.CreateDate.ShamciToFormatShamci(),
CreateTime = s.CreateTime,
TicketID = s.ID,
EndDate = s.EndDate.ShamciToFormatShamci(),
EndTime = s.EndTime,
Status = s.Status,
MsgStatus = s.Status.GetEnumDisplayName(),
Title = s.Title
})
.Paging(itemSerch.PageIndex, itemSerch.PageSize);
}
public async Task<Ticket?> GetTicketorgbyTicketID(int CompanyID, int TicketID)
{
return await _ticketRepo.Get(w => w.ID == TicketID
&& w.CompanyIDOrMobile == CompanyID.ToString()).FirstOrDefaultAsync();
}
public async Task<ICollection<SubTicketDTO>> GetSubTicket(int CompanyID, int TicketID)
{
#region AdvancedSearch
var invok = _subticketRepo
.Get(w => w.TicketID == TicketID && w.Ticket.CompanyIDOrMobile==CompanyID.ToString());
#endregion
//-----------------------
return await invok.OrderByDescending(o => o.ID).Select(s => new SubTicketDTO()
{
Date = s.Date.ShamciToFormatShamci(),
Text = s.Text,
Time = s.Time,
Type = s.Type,
MsgType = s.Type.GetEnumDisplayName()
})
.ToListAsync();
}
public async Task<bool> ExistTicketByTicketID(int TicketID)
{
return await _ticketRepo.Get(a => a.ID == TicketID && (a.Status != StatusTicket.End && a.Status != StatusTicket.optout)).AnyAsync();
}
public async Task<Ticket?> NewTicket(CTicketDto item, StatusTicket status = StatusTicket.Awaitingreview)
{
try
{
using var transaction =await _ticketRepo._dbContext.Database.BeginTransactionAsync();
var ticket = await _ticketRepo.AddAsync(new Ticket
{
CompanyIDOrMobile = item.CompanyID,
CreateDate = DateTime.Now.ConvertMiladiToShamsi(),
CreateTime = DateTime.Now.ToString("hh:mm tt"),
Title = item.Title,
Status = status
});
if (ticket.ID>0)
{
if (await _subticketRepo.AddBoolResultAsync(new SubTicket
{
Date = DateTime.Now.ConvertMiladiToShamsi(),
Time = DateTime.Now.ToString("hh:mm tt"),
TicketID = ticket.ID,
Text = item.Text,
Type = SideType.Customer
}))
{
await transaction.CommitAsync();
return ticket;
}
else
{
await transaction.RollbackAsync();
return null;
}
}
else
{
await transaction.RollbackAsync();
return null;
}
//_contextMongodb.InsertItem(new SysLog()
//{
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/NewTicket",
// Value = JsonConvert.SerializeObject(item),
// Route = _httpContextAccessor.HttpContext.Request.Path,
// Type = "User"
//});
}
catch (Exception ex)
{
//_contextMongodb.InsertItem(new SysLog()
//{
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/NewTicket",
// Value = ex.Message,
// Route = _httpContextAccessor.HttpContext.Request.Path,
// Type = "catch"
//});
return null;
}
}
public async Task<int?> NewPepole(string FullName, string Mobile)
{
try
{
var ID= _ticketUnknownPeopleRepo.Get(w=>w.Mobile==Mobile).Select(s=>s.ID).FirstOrDefault();
if (ID!=null && ID > 0)
var ID = _ticketUnknownPeopleRepo.Get(w => w.Mobile == Mobile).Select(s => s.ID).FirstOrDefault();
if (ID != null && ID > 0)
return ID;
var item=await _ticketUnknownPeopleRepo.AddAsync(new TiceketUnknownPeople
var item = await _ticketUnknownPeopleRepo.AddAsync(new TiceketUnknownPeople
{
FullName = FullName,
Mobile = Mobile
@@ -58,23 +181,15 @@ namespace Back.Services
}
}
public async Task<Ticket?> NewTicket(CTicketDto item, StatusTicket status = StatusTicket.Awaitingreview)
public async Task<bool> AddSubTicket(AddSubTicket item)
{
try
{
var ticket=await _ticketRepo.AddAsync(new Ticket
{
CompanyIDOrMobile = item.CompanyID,
CreateDate = DateTime.Now.ConvertMiladiToShamsi(),
CreateTime = DateTime.Now.ToString("hh:mm tt"),
Title = item.Title,
Status = status
});
await _subticketRepo.AddAsync(new SubTicket
return await _subticketRepo.AddBoolResultAsync(new SubTicket
{
Date = DateTime.Now.ConvertMiladiToShamsi(),
Time = DateTime.Now.ToString("hh:mm tt"),
TicketID = ticket.ID,
TicketID = item.TicketID,
Text = item.Text,
Type = SideType.Customer
});
@@ -82,12 +197,12 @@ namespace Back.Services
//{
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/NewTicket",
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddSubTicket",
// Value = JsonConvert.SerializeObject(item),
// Route = _httpContextAccessor.HttpContext.Request.Path,
// Type = "User"
//});
return ticket;
}
catch (Exception ex)
{
@@ -95,13 +210,46 @@ namespace Back.Services
//{
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/NewTicket",
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddSubTicket",
// Value = ex.Message,
// Route = _httpContextAccessor.HttpContext.Request.Path,
// Type = "catch"
//});
return null;
return false;
}
}
public async Task<bool> UpdateTicket(Ticket ticket)
{
try
{
return await _ticketRepo.UpdateAsync(ticket);
//_contextMongodb.InsertItem(new SysLog()
//{
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/UpdateTicket",
// Value = JsonConvert.SerializeObject(ticket),
// Route = _httpContextAccessor.HttpContext.Request.Path,
// Type = "User"
//});
}
catch (Exception ex)
{
//_contextMongodb.InsertItem(new SysLog()
//{
// TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier,
// Datetime = DateTime.Now.ConvertMiladiToShamsi(),
// Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/UpdateTicket",
// Value = ex.Message,
// Route = _httpContextAccessor.HttpContext.Request.Path,
// Type = "catch"
//});
return false;
}
}
}
}

View File

@@ -267,7 +267,7 @@ namespace Back.Services
if (user != null)
{
using var transaction = _RepoCompany._dbContext.Database.BeginTransaction();
using var transaction =await _RepoCompany._dbContext.Database.BeginTransactionAsync();
var company = user.RolUsers.First().Company;
company.Mobile = newUserName;
if (await _RepoCompany.UpdateAsync(company))
@@ -276,12 +276,12 @@ namespace Back.Services
user.Mobile = newUserName;
if (await _RepoUser.UpdateAsync(user))
{
transaction.Commit();
await transaction.CommitAsync();
return true;
}
else
{
transaction.Rollback();
await transaction.RollbackAsync();
return false;
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shared.DTOs
{
public class AddSubTicket
{
[Required]
public int TicketID { get; set; }
[Required]
public string Text { get; set; }
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shared.DTOs.Serch
{
public interface IFildGlobalItemSerch
{
public int PageIndex { get; set; }
public int PageSize { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shared.DTOs.Serch
{
public class ItemSerchGetTicket : IFildGlobalItemSerch
{
public int? TicketID { get; set; }
public string? Title { get; set; }
public int PageIndex { get; set; } = 1;
public int PageSize { get; set; } = 5;
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shared.DTOs
{
public class SubTicketDTO
{
public string Text { get; set; }
public string Date { get; set; }
public string Time { get; set; }
public SideType Type { get; set; }
public string MsgType { get; set; }
}
}

20
Shared/DTOs/TicketDTO.cs Normal file
View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shared.DTOs
{
public class TicketDTO
{
public int TicketID { get; set; }
public string Title { get; set; }
public string CreateDate { get; set; }
public string CreateTime { get; set; }
public string EndDate { get; set; }
public string EndTime { get; set; }
public StatusTicket Status { get; set; }
public string MsgStatus { get; set; }
}
}

View File

@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace Back.Common.Enums
namespace Shared.DTOs
{
public enum CustomerType:int
{

View File

@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace Back.Common.Enums
namespace Shared.DTOs
{
public enum InvoiceType:int
{

View File

@@ -1,5 +1,5 @@
using System.ComponentModel.DataAnnotations;
namespace Back.Common.Enums
namespace Shared.DTOs
{
public enum SentStatus
{

View File

@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace Back.Common.Enums
namespace Shared.DTOs
{
public enum SideType
{

View File

@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace Back.Common.Enums
namespace Shared.DTOs
{
public enum StatusOrder
{

View File

@@ -1,27 +1,20 @@
using System.ComponentModel.DataAnnotations;
using static Back.Common.ExclusiveAttribute;
namespace Back.Common.Enums
namespace Shared.DTOs
{
public enum StatusTicket
{
[Color("00FF23")]
[Display(Name = "فرد ناشناس")]
unknownPerson,
[Color("8844A3")]
[Display(Name = "در انتظار بررسی")]
Awaitingreview,
[Color("2CAFE8")]
[Display(Name = "خوانده شده/ در حال بررسی")]
Read_Checking,
[Color("4AB621")]
[Display(Name = "پاسخ داده شده")]
hasbeenanswered,
[Color("37363E")]
[Display(Name = "پاِیان")]
End,
[Color("D24249")]
[Display(Name = "انصراف")]
optout,
}