768 lines
29 KiB
C#
768 lines
29 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net.Sockets;
|
|
using _0_Framework.Application;
|
|
using AccountManagement.Application.Contracts.Task;
|
|
using AccountManagement.Application.Contracts.Ticket;
|
|
using AccountManagement.Domain.AccountAgg;
|
|
using AccountManagement.Domain.AdminResponseAgg;
|
|
using AccountManagement.Domain.AssignAgg;
|
|
using AccountManagement.Domain.ClientResponseAgg;
|
|
using AccountManagement.Domain.MediaAgg;
|
|
using AccountManagement.Domain.TaskAgg;
|
|
using AccountManagement.Domain.TicketAgg;
|
|
|
|
namespace AccountManagement.Application;
|
|
|
|
public class TicketApplication : ITicketApplication
|
|
{
|
|
private readonly ITicketRepository _ticketRepository;
|
|
private readonly IAccountRepository _accountRepository;
|
|
private readonly ITaskRepository _taskRepository;
|
|
private readonly IAssignRepository _assignRepository;
|
|
private readonly IMediaRepository _mediaRepository;
|
|
|
|
public TicketApplication(ITicketRepository ticketRepository, IAccountRepository accountRepository, ITaskRepository taskRepository, IAssignRepository assignRepository, IMediaRepository mediaRepository)
|
|
{
|
|
_ticketRepository = ticketRepository;
|
|
_accountRepository = accountRepository;
|
|
_taskRepository = taskRepository;
|
|
_assignRepository = assignRepository;
|
|
_mediaRepository = mediaRepository;
|
|
}
|
|
|
|
public OperationResult CreateTicket(CreateTicket command)
|
|
{
|
|
var operation = new OperationResult();
|
|
if (string.IsNullOrWhiteSpace(command.ContractingPartyName))
|
|
{
|
|
return operation.Failed("خطای سیستمی");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(command.Title))
|
|
{
|
|
return operation.Failed("لطفا عنوان را وارد کنید");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(command.Description))
|
|
{
|
|
return operation.Failed("لطفا توضیحات خودرا وارد کنید");
|
|
}
|
|
|
|
|
|
|
|
var ticket = new Ticket(command.Title, command.Description, command.SenderId, command.ContractingPartyName,
|
|
command.TicketType);
|
|
_ticketRepository.Create(ticket);
|
|
_ticketRepository.SaveChanges();
|
|
#region SaveDocuments
|
|
|
|
if ((command.Document1?.Length > 5000000) || (command.Document2?.Length > 5000000) || (command.Document3?.Length > 5000000) || (command.Document4?.Length > 5000000)
|
|
|| (command.Document5?.Length > 5000000))
|
|
return operation.Failed("حجم فایل نمیتواند از 5 مگابایت بیشتر باشد");
|
|
|
|
|
|
if (command.Document1?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"Ticket", $"{ticket.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document1.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document1.CopyTo(stream);
|
|
}
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateTicketMedia(ticket.id, media.id);
|
|
}
|
|
if (command.Document2?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"Ticket", $"{ticket.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document2.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document2.CopyTo(stream);
|
|
}
|
|
var type = Path.GetExtension(filepath);
|
|
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateTicketMedia(ticket.id, media.id);
|
|
}
|
|
if (command.Document3?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"Ticket", $"{ticket.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document3.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document3.CopyTo(stream);
|
|
}
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateTicketMedia(ticket.id, media.id);
|
|
}
|
|
if (command.Document4?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"Ticket", $"{ticket.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document4.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document4.CopyTo(stream);
|
|
}
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateTicketMedia(ticket.id, media.id);
|
|
}
|
|
if (command.Document5?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"Ticket", $"{ticket.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document5.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document5.CopyTo(stream);
|
|
}
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateTicketMedia(ticket.id, media.id);
|
|
}
|
|
if (command.ScreenShot?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"Ticket", $"{ticket.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.ScreenShot.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.ScreenShot.CopyTo(stream);
|
|
}
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateTicketMedia(ticket.id, media.id);
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
#region SaveVoice
|
|
if (command.Voice?.Length > 0)
|
|
{
|
|
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"Ticket", $"{ticket.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Voice.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Voice.CopyTo(stream);
|
|
}
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateTicketMedia(ticket.id, media.id);
|
|
|
|
}
|
|
#endregion
|
|
|
|
_mediaRepository.SaveChanges();
|
|
return operation.Succcedded(ticket.id);
|
|
}
|
|
|
|
public OperationResult AssignTicket(CreateTask command, long ticketId)
|
|
{
|
|
var operation = new OperationResult();
|
|
if (string.IsNullOrEmpty(command.Title))
|
|
{
|
|
return operation.Failed("لطفا عنوان وظیفه خود ار وارد کنید");
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(command.EndTaskDate))
|
|
{
|
|
return operation.Failed("لطفا تاریخ انجام وظیفه را وارد کنید");
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(command.ContractingPartyName))
|
|
{
|
|
return operation.Failed("لطفا طرف حساب خودرا وارد کنید");
|
|
}
|
|
|
|
if (command.SenderId < 1)
|
|
{
|
|
return operation.Failed("خطای سیستمی!!!");
|
|
}
|
|
|
|
var sender = _accountRepository.GetIncludePositions(command.SenderId);
|
|
|
|
|
|
if (command.ReceiverId.Count < 1)
|
|
{
|
|
return operation.Failed("طرف وظیفه خود را وارد کنید");
|
|
}
|
|
|
|
var receivers = _accountRepository.GetAccountsByIds(command.ReceiverId);
|
|
|
|
if (sender.Position.PositionValue == 1)
|
|
{
|
|
|
|
}
|
|
else if (receivers.Any(x => sender.Position.PositionValue >= x.Position.PositionValue))
|
|
{
|
|
var checkReceiver = receivers.Where(x => sender.Position.PositionValue >= x.Position.PositionValue).ToList();
|
|
if (checkReceiver.All(x => x.id == sender.id))
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
return operation.Failed("شما نمیتوانید به سطح بالاتر خود یا هم سطح خود وظیفه ای دهید");
|
|
}
|
|
|
|
}
|
|
else if (receivers.Count == 1 && receivers.Any(x => sender.id == x.id))
|
|
{
|
|
|
|
}
|
|
|
|
|
|
var endTask = string.IsNullOrWhiteSpace(command.EndTaskTime) ? command.EndTaskDate.ToGeorgianDateTime2() : command.EndTaskDate.ToGeorgianDateWithTime(command.EndTaskTime);
|
|
|
|
var task = new Tasks(command.Title, endTask, command.Description, command.SenderId, command.ContractingPartyName, ticketId);
|
|
_taskRepository.Create(task);
|
|
_assignRepository.SaveChanges();
|
|
foreach (var receiver in receivers)
|
|
{
|
|
var assign = new Assign(task.id, task.SenderId, receiver.id, sender.Position.PositionValue, receiver.Fullname,
|
|
receiver.Position.PositionValue);
|
|
_assignRepository.Create(assign);
|
|
}
|
|
|
|
|
|
|
|
#region SaveMedias
|
|
|
|
#region SaveDocuments
|
|
|
|
if ((command.Document1?.Length > 5000000) || (command.Document2?.Length > 5000000) || (command.Document3?.Length > 5000000) || (command.Document4?.Length > 5000000)
|
|
|| (command.Document5?.Length > 5000000) || (command.Document6?.Length > 5000000))
|
|
return operation.Failed("حجم فایل نمیتواند از 5 مگابایت بیشتر باشد");
|
|
|
|
|
|
if (command.Document1?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"Task", $"{task.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document1.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document1.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
|
}
|
|
if (command.Document2?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"Task", $"{task.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document2.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document2.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
|
}
|
|
if (command.Document3?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"Task", $"{task.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document3.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document3.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
|
}
|
|
if (command.Document4?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"Task", $"{task.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document4.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document4.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
|
}
|
|
if (command.Document5?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"Task", $"{task.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document5.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document5.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
|
}
|
|
if (command.Document6?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"Task", $"{task.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document6.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document6.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
#region SaveVoice
|
|
if (command.Voice?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"Task", $"{task.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Voice.FileName);
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Voice.CopyTo(stream);
|
|
}
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "صوت");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateMediaWithTaskMedia(task.id, media.id);
|
|
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
_taskRepository.SaveChanges();
|
|
|
|
return operation.Succcedded(task.id);
|
|
}
|
|
|
|
public OperationResult CompleteTicket(long id)
|
|
{
|
|
var operation = new OperationResult();
|
|
if (!_ticketRepository.Exists(x => x.id == id))
|
|
{
|
|
return operation.Failed("چنین تیکتی وجود ندارد");
|
|
}
|
|
var ticket = _ticketRepository.Get(id);
|
|
ticket.Completed();
|
|
_ticketRepository.SaveChanges();
|
|
return operation.Succcedded(ticket.id);
|
|
}
|
|
|
|
public OperationResult AdminResponseTicket(ResponseTicket command)
|
|
{
|
|
var operation = new OperationResult();
|
|
if (string.IsNullOrWhiteSpace(command.Response))
|
|
{
|
|
return operation.Failed("لطفا پیغام خود را وارد کنبد");
|
|
}
|
|
|
|
var adminRes = new AdminResponse(command.Response, command.TicketId);
|
|
_ticketRepository.CreateAdminResponse(adminRes);
|
|
_ticketRepository.SaveChanges();
|
|
|
|
#region SaveDocuments
|
|
|
|
if ((command.Document1?.Length > 5000000) || (command.Document2?.Length > 5000000) || (command.Document3?.Length > 5000000) || (command.Document4?.Length > 5000000)
|
|
|| (command.Document5?.Length > 5000000) || (command.Document6?.Length > 5000000))
|
|
return operation.Failed("حجم فایل نمیتواند از 5 مگابایت بیشتر باشد");
|
|
|
|
|
|
if (command.Document1?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"TicketAdminResponse", $"{adminRes.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document1.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document1.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateAdminResponseMedia(adminRes.id, media.id);
|
|
}
|
|
if (command.Document2?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"TicketAdminResponse", $"{adminRes.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document2.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document2.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateAdminResponseMedia(adminRes.id, media.id);
|
|
}
|
|
if (command.Document3?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"TicketAdminResponse", $"{adminRes.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document3.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document3.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateAdminResponseMedia(adminRes.id, media.id);
|
|
}
|
|
if (command.Document4?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"TicketAdminResponse", $"{adminRes.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document4.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document4.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateAdminResponseMedia(adminRes.id, media.id);
|
|
}
|
|
if (command.Document5?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"TicketAdminResponse", $"{adminRes.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document5.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document5.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateAdminResponseMedia(adminRes.id, media.id);
|
|
}
|
|
|
|
if (command.Document6?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost",
|
|
"Storage",
|
|
"TicketAdminResponse", $"{adminRes.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document6.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document6.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateAdminResponseMedia(adminRes.id, media.id);
|
|
|
|
|
|
}
|
|
|
|
#endregion
|
|
_mediaRepository.SaveChanges();
|
|
|
|
|
|
return operation.Succcedded(adminRes.id);
|
|
}
|
|
|
|
public OperationResult ClientResponseTicket(ResponseTicket command)
|
|
{
|
|
var operation = new OperationResult();
|
|
if (string.IsNullOrWhiteSpace(command.Response))
|
|
{
|
|
return operation.Failed("لطفا پیغام خود را وارد کنبد");
|
|
}
|
|
|
|
var clientRes = new ClientResponse(command.Response, command.TicketId);
|
|
_ticketRepository.CreateClientResponse(clientRes);
|
|
_ticketRepository.SaveChanges();
|
|
#region SaveDocuments
|
|
|
|
if ((command.Document1?.Length > 5000000) || (command.Document2?.Length > 5000000) || (command.Document3?.Length > 5000000) || (command.Document4?.Length > 5000000)
|
|
|| (command.Document5?.Length > 5000000) || (command.Document6?.Length > 5000000))
|
|
return operation.Failed("حجم فایل نمیتواند از 5 مگابایت بیشتر باشد");
|
|
|
|
|
|
if (command.Document1?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"TicketClientResponse", $"{clientRes.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document1.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document1.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateClientResponseMedia(clientRes.id, media.id);
|
|
|
|
}
|
|
if (command.Document2?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"TicketClientResponse", $"{clientRes.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document2.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document2.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateClientResponseMedia(clientRes.id, media.id);
|
|
}
|
|
if (command.Document3?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"TicketClientResponse", $"{clientRes.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document3.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document3.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateClientResponseMedia(clientRes.id, media.id);
|
|
}
|
|
if (command.Document4?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"TicketClientResponse", $"{clientRes.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document4.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document4.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateClientResponseMedia(clientRes.id, media.id);
|
|
}
|
|
if (command.Document5?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost", "Storage",
|
|
"TicketClientResponse", $"{clientRes.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document5.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document5.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateClientResponseMedia(clientRes.id, media.id);
|
|
}
|
|
|
|
if (command.Document6?.Length > 0)
|
|
{
|
|
var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "ServiceHost",
|
|
"Storage",
|
|
"TicketClientResponse", $"{clientRes.id}");
|
|
Directory.CreateDirectory(path);
|
|
|
|
string filepath = Path.Combine(path, command.Document6.FileName);
|
|
|
|
using (var stream = new FileStream(filepath, FileMode.Create))
|
|
{
|
|
command.Document6.CopyTo(stream);
|
|
|
|
}
|
|
|
|
var type = Path.GetExtension(filepath);
|
|
var media = new Media(filepath, type, "فایل");
|
|
_mediaRepository.Create(media);
|
|
_mediaRepository.SaveChanges();
|
|
_mediaRepository.CreateClientResponseMedia(clientRes.id, media.id);
|
|
|
|
|
|
}
|
|
|
|
#endregion
|
|
_mediaRepository.SaveChanges();
|
|
return operation.Succcedded(clientRes.id);
|
|
}
|
|
|
|
public EditTicket GetDetails(long id)
|
|
{
|
|
return _ticketRepository.GetDetails(id);
|
|
}
|
|
|
|
public List<TicketViewModel> GetAll(TicketSearchModel searchModel)
|
|
{
|
|
return _ticketRepository.GetAll(searchModel);
|
|
}
|
|
|
|
public bool IsExist(long id)
|
|
{
|
|
return _ticketRepository.Exists(x => x.id == id);
|
|
}
|
|
} |