153 lines
5.7 KiB
C#
153 lines
5.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using _0_Framework.Application;
|
|
using _0_Framework.InfraStructure;
|
|
using AccountManagement.Application.Contracts.Media;
|
|
using AccountManagement.Application.Contracts.Ticket;
|
|
using AccountManagement.Domain.AdminResponseAgg;
|
|
using AccountManagement.Domain.ClientResponseAgg;
|
|
using AccountManagement.Domain.TicketAgg;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace AccountMangement.Infrastructure.EFCore.Repository;
|
|
|
|
public class TicketRepository : RepositoryBase<long, Ticket>, ITicketRepository
|
|
{
|
|
private readonly AccountContext _accountContext;
|
|
public TicketRepository(AccountContext accountContext) : base(accountContext)
|
|
{
|
|
_accountContext = accountContext;
|
|
}
|
|
|
|
public List<TicketViewModel> GetAll(TicketSearchModel searchModel)
|
|
{
|
|
var query = _accountContext.Tickets.OrderByDescending(x => x.CreationDate).Select(x => new TicketViewModel()
|
|
{
|
|
Description = x.Description,
|
|
SenderId = x.SenderId,
|
|
ContractingPartyName = x.ContractingPartyName,
|
|
Id = x.id,
|
|
Title = x.Title,
|
|
TicketType = x.TicketType,
|
|
Status = x.Status,
|
|
TaskId = x.TaskId,
|
|
CreationDateTimeGr = x.CreationDate,
|
|
CreationDateTime = x.CreationDate.ToFarsiFull(),
|
|
MediaViewModels = _accountContext.TicketMedias.Include(z => z.Media).Where(a => a.TicketId == x.id)
|
|
.Select(m => new MediaViewModel()
|
|
{
|
|
Id = m.Media.id,
|
|
Path = m.Media.Path,
|
|
Type = m.Media.Type,
|
|
}).ToList(),
|
|
AdminResponseViewModels = _accountContext.AdminResponses.Include(a => a.AdminResponseMedias)
|
|
.Where(a => a.TicketId == x.id).Select(a => new AdminResponseViewModel()
|
|
{
|
|
MediaViewModels = _accountContext.AdminResponseMedias.Include(d => d.Media)
|
|
.Where(d => d.AdminResponseId == a.id).Select(d => new MediaViewModel()
|
|
{
|
|
Id = d.Media.id,
|
|
Path = d.Media.Path,
|
|
Type = d.Media.Type,
|
|
}).ToList(),
|
|
Response = a.Response,
|
|
TicketId = a.TicketId
|
|
}).ToList(),
|
|
ClientResponseViewModels = _accountContext.ClientResponses.Include(a => a.ClientResponseMedias)
|
|
.Where(a => a.TicketId == x.id).Select(a => new ClientResponseViewModel()
|
|
{
|
|
MediaViewModels = _accountContext.ClientResponseMedias.Include(d => d.Media)
|
|
.Where(d => d.ClientResponseId == a.id).Select(d => new MediaViewModel()
|
|
{
|
|
Id = d.Media.id,
|
|
Path = d.Media.Path,
|
|
Type = d.Media.Type,
|
|
}).ToList(),
|
|
Response = a.Response,
|
|
TicketId = a.TicketId
|
|
}).ToList(),
|
|
|
|
});
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.ContractingPartyName))
|
|
{
|
|
query = query.Where(x => x.ContractingPartyName.Contains(searchModel.ContractingPartyName));
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.Status))
|
|
{
|
|
query = query.Where(x => x.Status == searchModel.Status);
|
|
}
|
|
|
|
if (!(string.IsNullOrWhiteSpace(searchModel.StartDate) && string.IsNullOrWhiteSpace(searchModel.EndDate)))
|
|
{
|
|
if (string.IsNullOrWhiteSpace(searchModel.OneDay))
|
|
{
|
|
var startDate = searchModel.StartDate.ToGeorgianDateTime();
|
|
var endDate = searchModel.EndDate.ToGeorgianDateTime();
|
|
query = query.Where(x => startDate < x.CreationDateTimeGr && endDate > x.CreationDateTimeGr);
|
|
}
|
|
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.Title))
|
|
{
|
|
query = query.Where(x => x.Title.Contains(searchModel.Title));
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.TypeOfTicket))
|
|
{
|
|
query = query.Where(x => x.TicketType == searchModel.TypeOfTicket);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.OneDay))
|
|
{
|
|
var day = searchModel.OneDay.ToGeorgianDateTime();
|
|
query = query.Where(x => x.CreationDateTimeGr.Date == day.Date);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.IsAssigned))
|
|
{
|
|
var isAssigned = bool.Parse(searchModel.IsAssigned);
|
|
if (isAssigned)
|
|
{
|
|
query.Where(x => x.TaskId != null);
|
|
}
|
|
else if (!isAssigned)
|
|
{
|
|
query.Where(x => x.TaskId == null);
|
|
}
|
|
}
|
|
return query.ToList();
|
|
}
|
|
|
|
public void CreateAdminResponse(AdminResponse command)
|
|
{
|
|
_accountContext.Add(command);
|
|
}
|
|
|
|
public void CreateClientResponse(ClientResponse command)
|
|
{
|
|
_accountContext.Add(command);
|
|
}
|
|
|
|
public EditTicket GetDetails(long id)
|
|
{
|
|
return _accountContext.Tickets.Select(x => new EditTicket()
|
|
{
|
|
ContractingPartyName = x.ContractingPartyName,
|
|
Description = x.Description,
|
|
Id = x.id,
|
|
SenderId = x.SenderId,
|
|
TicketType = x.TicketType,
|
|
Title = x.Title,
|
|
MediaViewModels = _accountContext.TicketMedias.Include(z => z.Media).Where(a => a.TicketId == x.id)
|
|
.Select(m => new MediaViewModel()
|
|
{
|
|
Id = m.Media.id,
|
|
Path = m.Media.Path,
|
|
Type = m.Media.Type,
|
|
}).ToList(),
|
|
}).FirstOrDefault(x => x.Id == id);
|
|
}
|
|
} |