626 lines
16 KiB
C#
626 lines
16 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.Diagnostics;
|
|
using _0_Framework.Application;
|
|
using AccountManagement.Application.Contracts.Account;
|
|
using AccountManagement.Application.Contracts.Assign;
|
|
using AccountManagement.Application.Contracts.Position;
|
|
using AccountManagement.Application.Contracts.Task;
|
|
using AccountManagement.Domain.MediaAgg;
|
|
using CompanyManagment.App.Contracts.Checkout;
|
|
using CompanyManagment.App.Contracts.Contract;
|
|
using CompanyManagment.App.Contracts.Leave;
|
|
using CompanyManagment.App.Contracts.Workshop;
|
|
using CompanyManagment.Application;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
|
|
|
|
namespace ServiceHost.Areas.AdminNew.Pages.Company.Task
|
|
{
|
|
public class IndexModel : PageModel
|
|
{
|
|
private readonly ITaskApplication _taskApplication;
|
|
private readonly IAuthHelper _authHelper;
|
|
private readonly IAccountApplication _accountApplication;
|
|
private readonly IPositionApplication _positionApplication;
|
|
private readonly IWebHostEnvironment _environment;
|
|
|
|
public IndexModel(ITaskApplication taskApplication, IAuthHelper authHelper,
|
|
IAccountApplication accountApplication, IPositionApplication positionApplication,
|
|
IWebHostEnvironment environment)
|
|
{
|
|
_taskApplication = taskApplication;
|
|
_authHelper = authHelper;
|
|
_accountApplication = accountApplication;
|
|
_positionApplication = positionApplication;
|
|
_environment = environment;
|
|
}
|
|
|
|
public List<TaskViewModel> TaskViewModels { get; set; }
|
|
public TaskSearchModel SearchModel { get; set; }
|
|
public int RequestCount { get; set; }
|
|
|
|
|
|
|
|
public IActionResult OnGet(TaskSearchModel searchModel)
|
|
{
|
|
if (_authHelper.GetPermissions().Any(x => x == 901))
|
|
{
|
|
//var serach = new TaskSearchModel();
|
|
searchModel.PageIndex = 0;
|
|
SearchModel = searchModel;
|
|
RequestCount = _taskApplication.GetRequestedTasksCount();
|
|
return Page();
|
|
}
|
|
else
|
|
{
|
|
return Forbid();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public IActionResult OnGetTaskPagination(int pageIndex, string startDate, string endDate, long accountId,
|
|
string isDone,
|
|
string isCanceled, string isCancelRequest, string isTimeRequest, string timeRequestAccepted, string type, string isDoneRequest)
|
|
{
|
|
|
|
var searchModel = new TaskSearchModel()
|
|
{
|
|
IsDone = isDone,
|
|
IsDoneRequest = isDoneRequest,
|
|
IsCancelRequest = isCancelRequest,
|
|
AccountId = accountId,
|
|
EndDate = endDate,
|
|
IsCanceled = isCanceled,
|
|
IsTimeRequest = isTimeRequest,
|
|
PageIndex = pageIndex,
|
|
StartDate = startDate,
|
|
TimeRequestAccepted = timeRequestAccepted,
|
|
TypeOfTicket = type
|
|
|
|
};
|
|
|
|
var taskList = new List<TaskViewModel>();
|
|
|
|
taskList = searchModel.TypeOfTicket == "request"
|
|
? _taskApplication.GetAllRequestedTasks(searchModel)
|
|
: _taskApplication.GetTasks(searchModel);
|
|
|
|
|
|
|
|
return new JsonResult(new
|
|
{
|
|
pageIndex = taskList.Count,
|
|
taskList = taskList,
|
|
positions = _positionApplication.GetLowerPosition()
|
|
});
|
|
}
|
|
|
|
public IActionResult OnGetRequestCount()
|
|
{
|
|
var requestCount = _taskApplication.GetRequestedTasksCount();
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = true,
|
|
result = requestCount
|
|
});
|
|
}
|
|
|
|
// برای ارجاع دادن
|
|
public IActionResult OnPostCreateAssign(OperationModalViewModel command)
|
|
{
|
|
if (_authHelper.GetPermissions().Any(x => x == 90110))
|
|
{
|
|
|
|
var assign = new CreateAssign()
|
|
{
|
|
AssignerPositionValue = (int)_authHelper.CurrentAccountInfo().PositionValue,
|
|
AssignedId = command.CreateAssign.AssignedId,
|
|
AssignerId = _authHelper.CurrentAccountId(),
|
|
TaskId = command.TaskId
|
|
};
|
|
var res = _taskApplication.CreateAssign(assign);
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = res.IsSuccedded,
|
|
message = res.Message,
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
return Forbid();
|
|
}
|
|
|
|
}
|
|
|
|
// برای مهلت زمانی
|
|
public IActionResult OnPostCreateTimeRequest(OperationModalViewModel command)
|
|
{
|
|
if (_authHelper.GetPermissions().Any(x => x == 90111))
|
|
{
|
|
var requestTime = new CreateTaskTimeRequest()
|
|
{
|
|
Description = command.CreateTaskTimeRequest.Description,
|
|
RequestTime = command.CreateTaskTimeRequest.RequestTime,
|
|
TaskId = command.TaskId
|
|
};
|
|
var res = _taskApplication.CreateRequestTime(requestTime);
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = res.IsSuccedded,
|
|
message = res.Message,
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
return Forbid();
|
|
}
|
|
|
|
}
|
|
|
|
// برای تایید درخواست مهلت
|
|
public IActionResult OnPostAcceptTimeRequest(long id)
|
|
{
|
|
var res = _taskApplication.AcceptRequestDatetime(id);
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = res.IsSuccedded,
|
|
message = res.Message,
|
|
|
|
});
|
|
}
|
|
|
|
// برای لغو درخواست مهلت
|
|
public IActionResult OnPostRejectTimeRequest(long id)
|
|
{
|
|
var res = _taskApplication.RejectTimeRequest(id);
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = res.IsSuccedded,
|
|
message = res.Message,
|
|
|
|
});
|
|
}
|
|
|
|
// برای درخواست انصراف
|
|
public IActionResult OnPostCreateCancelRequest(OperationModalViewModel command)
|
|
{
|
|
var requestCancel = new CreateTaskCancel()
|
|
{
|
|
Description = command.CreateTaskCancel.Description,
|
|
TaskId = command.TaskId
|
|
};
|
|
var res = _taskApplication.CreateCancelRequest(requestCancel);
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = res.IsSuccedded,
|
|
message = res.Message,
|
|
|
|
});
|
|
}
|
|
|
|
// برای تایید انصراف
|
|
public IActionResult OnPostAcceptCancel(long id)
|
|
{
|
|
var res = _taskApplication.AcceptCancelRequest(id);
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = res.IsSuccedded,
|
|
message = res.Message,
|
|
|
|
});
|
|
}
|
|
|
|
// برای لغو انصراف
|
|
public IActionResult OnPostRejectCancel(long id)
|
|
{
|
|
var res = _taskApplication.RejectCancelRequest(id);
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = res.IsSuccedded,
|
|
message = res.Message,
|
|
|
|
});
|
|
}
|
|
|
|
// برای انجام تسک
|
|
public IActionResult OnPostComplete(OperationModalViewModel command)
|
|
{
|
|
var completeTask = new CompleteTaskViewModel()
|
|
{
|
|
Description = command.CompleteTaskViewModel.Description,
|
|
Id = command.TaskId
|
|
};
|
|
|
|
var res = _taskApplication.CreateCompleteTaskRequest(completeTask);
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = res.IsSuccedded,
|
|
message = res.Message,
|
|
|
|
});
|
|
}
|
|
|
|
public IActionResult OnPostAcceptComplete(long id)
|
|
{
|
|
var res = _taskApplication.AcceptCompleteRequest(id);
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = res.IsSuccedded,
|
|
message = res.Message,
|
|
|
|
});
|
|
}
|
|
public IActionResult OnPostRejectComplete(long id)
|
|
{
|
|
var res = _taskApplication.RejectCompleteRequest(id);
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = res.IsSuccedded,
|
|
message = res.Message,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// برای باز کردن مودال عملیات تسک
|
|
public IActionResult OnGetAssignTo(long taskId, string type)
|
|
{
|
|
if (_authHelper.GetPermissions().Any(x => x == 90110))
|
|
{
|
|
var model = new OperationModalViewModel()
|
|
{
|
|
TaskId = taskId,
|
|
Type = type,
|
|
Accounts = _accountApplication.AccountsForAssign(taskId)
|
|
};
|
|
return Partial("OperationModal", model);
|
|
}
|
|
|
|
else
|
|
{
|
|
return Forbid();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// برای باز کردن مودال عملیات درخواست تسک
|
|
public IActionResult OnGetOperationRequestTask(long taskId, string type)
|
|
{
|
|
var model = new OperationModalViewModel()
|
|
{
|
|
ModalTaskRequest = _taskApplication.GetRequestDetails(taskId),
|
|
TaskId = taskId,
|
|
Type = type,
|
|
Accounts = _accountApplication.AccountsForAssign(taskId)
|
|
};
|
|
return Partial("OperationRequestModal", model);
|
|
}
|
|
|
|
|
|
|
|
|
|
// برای باز کردن مودال جزئیات تسک مثل عنوان، تاریخ، توضیحات و ...
|
|
public IActionResult OnGetDetailsTask(long taskId)
|
|
{
|
|
if (_authHelper.GetPermissions().Any(x => x == 90113))
|
|
{
|
|
var model = _taskApplication.GetDetails(taskId);
|
|
return Partial("DetailsModal", model);
|
|
}
|
|
else
|
|
{
|
|
return Forbid();
|
|
}
|
|
|
|
}
|
|
|
|
#region Show and Download Files
|
|
|
|
public IActionResult OnGetGetFile(string filePath, long id)
|
|
{
|
|
if (string.IsNullOrEmpty(filePath))
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
|
|
if (!System.IO.File.Exists(filePath))
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
var contentType = GetContentTypeImage(Path.GetExtension(filePath));
|
|
if (string.IsNullOrWhiteSpace(contentType))
|
|
{
|
|
byte[] fileContent = System.IO.File.ReadAllBytes(filePath);
|
|
var extension = GetContentType(Path.GetExtension(filePath));
|
|
return File(fileContent, extension, $"Task_{id}{Path.GetExtension(filePath)}");
|
|
}
|
|
else
|
|
{
|
|
return PhysicalFile(filePath, contentType);
|
|
}
|
|
|
|
}
|
|
|
|
public IActionResult OnGetShowVoice(string filePath)
|
|
{
|
|
if (string.IsNullOrEmpty(filePath))
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
|
|
if (!System.IO.File.Exists(filePath))
|
|
{
|
|
return NotFound();
|
|
}
|
|
byte[] voiceContent = System.IO.File.ReadAllBytes(filePath);
|
|
return File(voiceContent, "audio/ogg", $"Task_voice.ogg");
|
|
|
|
}
|
|
|
|
|
|
public IActionResult OnGetShowPicture(string filePath)
|
|
{
|
|
if (string.IsNullOrEmpty(filePath))
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
|
|
if (!System.IO.File.Exists(filePath))
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
var contentType = GetContentTypeImage(Path.GetExtension(filePath));
|
|
return PhysicalFile(filePath, contentType);
|
|
}
|
|
|
|
private string GetContentTypeImage(string extension)
|
|
{
|
|
if (!extension.StartsWith("."))
|
|
{
|
|
extension = "." + extension;
|
|
}
|
|
|
|
return extension.ToLower() switch
|
|
{
|
|
".jpg" => "image/jpeg",
|
|
".jpeg" => "image/jpeg",
|
|
".png" => "image/png",
|
|
".gif" => "image/gif",
|
|
".bmp" => "image/bmp",
|
|
".svg" => "image/svg+xml",
|
|
".ico" => "image/x-icon",
|
|
_ => "",
|
|
};
|
|
}
|
|
|
|
public static string GetContentType(string extension)
|
|
{
|
|
|
|
// Ensure the extension starts with a dot
|
|
if (!extension.StartsWith("."))
|
|
{
|
|
extension = "." + extension;
|
|
}
|
|
|
|
// Use switch expression to return the appropriate content type
|
|
return extension.ToLower() switch
|
|
{
|
|
".txt" => "text/plain",
|
|
".htm" => "text/html",
|
|
".html" => "text/html",
|
|
".css" => "text/css",
|
|
".js" => "application/javascript",
|
|
".json" => "application/json",
|
|
".xml" => "application/xml",
|
|
".pdf" => "application/pdf",
|
|
".zip" => "application/zip",
|
|
".rar" => "application/x-rar-compressed",
|
|
".tar" => "application/x-tar",
|
|
".mp3" => "audio/mpeg",
|
|
".wav" => "audio/wav",
|
|
".mp4" => "video/mp4",
|
|
".avi" => "video/x-msvideo",
|
|
".doc" => "application/msword",
|
|
".docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
".xls" => "application/vnd.ms-excel",
|
|
".xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
".ppt" => "application/vnd.ms-powerpoint",
|
|
".pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
_ => "application/octet-stream",
|
|
};
|
|
}
|
|
|
|
#endregion
|
|
|
|
public IActionResult OnPostRemoveTask(long taskId)
|
|
{
|
|
if (_authHelper.GetPermissions().Any(x => x == 90115))
|
|
{
|
|
var res = _taskApplication.RemoveTask(taskId);
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = res.IsSuccedded,
|
|
message = res.Message,
|
|
});
|
|
}
|
|
else
|
|
{
|
|
return Forbid();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
// برای تغییر تاریخ درخواست تسک
|
|
public IActionResult OnPostChangeTime(string time, long taskId)
|
|
{
|
|
var res = _taskApplication.ChangeRequestTimeAndAccept(time, taskId);
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = res.IsSuccedded,
|
|
message = res.Message,
|
|
});
|
|
}
|
|
|
|
|
|
|
|
public IActionResult OnGetEditTask(long taskId)
|
|
{
|
|
if (_authHelper.GetPermissions().Any(x => x == 90114))
|
|
{
|
|
var model = new EditTaskPartialViewModel()
|
|
{
|
|
Id = _authHelper.CurrentAccountId(),
|
|
AccountList = _accountApplication.GetAccountLowerPositionvalue().Select(x => new AccountViewModel()
|
|
{
|
|
Id = x.Id,
|
|
Fullname = x.Fullname
|
|
}).ToList(),
|
|
EditTask = _taskApplication.GetDetails(taskId)
|
|
};
|
|
return Partial("Edit", model);
|
|
}
|
|
else
|
|
{
|
|
return Forbid();
|
|
}
|
|
|
|
|
|
|
|
//var index = 1;
|
|
//var medias = model.EditTask.medias.Where(x => x.Category == "فایل").ToList();
|
|
//foreach (var media in medias)
|
|
//{
|
|
// switch (index)
|
|
// {
|
|
// case 1:
|
|
// using (var stream = System.IO.File.OpenRead(media.Path))
|
|
// {
|
|
// model.EditTask.Document1 = new FormFile(stream, 0, stream.Length, $"{taskId}_1",
|
|
// Path.GetFileName(stream.Name));
|
|
// }
|
|
// break;
|
|
// case 2:
|
|
// using (var stream = System.IO.File.OpenRead(media.Path))
|
|
// {
|
|
// model.EditTask.Document2 = new FormFile(stream, 0, stream.Length, $"{taskId}_2",
|
|
// Path.GetFileName(stream.Name));
|
|
// }
|
|
// break;
|
|
// case 3:
|
|
// using (var stream = System.IO.File.OpenRead(media.Path))
|
|
// {
|
|
// model.EditTask.Document3 = new FormFile(stream, 0, stream.Length, $"{taskId}_3",
|
|
// Path.GetFileName(stream.Name));
|
|
// }
|
|
// break;
|
|
// case 4:
|
|
// using (var stream = System.IO.File.OpenRead(media.Path))
|
|
// {
|
|
// model.EditTask.Document4 = new FormFile(stream, 0, stream.Length, $"{taskId}_4",
|
|
// Path.GetFileName(stream.Name));
|
|
// }
|
|
// break;
|
|
// case 5:
|
|
// using (var stream = System.IO.File.OpenRead(media.Path))
|
|
// {
|
|
// model.EditTask.Document5 = new FormFile(stream, 0, stream.Length, $"{taskId}_5",
|
|
// Path.GetFileName(stream.Name));
|
|
// }
|
|
// break;
|
|
// case 6:
|
|
// using (var stream = System.IO.File.OpenRead(media.Path))
|
|
// {
|
|
// model.EditTask.Document6 = new FormFile(stream, 0, stream.Length, $"{taskId}_6",
|
|
// Path.GetFileName(stream.Name));
|
|
// }
|
|
// break;
|
|
// }
|
|
|
|
// index++;
|
|
//}
|
|
|
|
//var voice = model.EditTask.medias.FirstOrDefault(x => x.Category == "صوت");
|
|
//if (voice != null)
|
|
//{
|
|
// using (var stream = System.IO.File.OpenRead(voice.Path))
|
|
// {
|
|
// model.EditTask.Voice = new FormFile(stream, 0, stream.Length, $"{taskId}_v",
|
|
// Path.GetFileName(stream.Name));
|
|
// }
|
|
//}
|
|
|
|
|
|
}
|
|
|
|
public IActionResult OnPostEditSaveTask(EditTaskPartialViewModel command)
|
|
{
|
|
var editCommand = new EditTask()
|
|
{
|
|
CompleteDescription = command.EditTask.CompleteDescription,
|
|
ContractingPartyName = command.EditTask.ContractingPartyName,
|
|
Description = command.EditTask.Description,
|
|
Document1 = command.EditTask.Document1,
|
|
Document2 = command.EditTask.Document2,
|
|
Document3 = command.EditTask.Document3,
|
|
Document4 = command.EditTask.Document4,
|
|
Document5 = command.EditTask.Document5,
|
|
Document6 = command.EditTask.Document6,
|
|
Voice = command.EditTask.Voice,
|
|
EndTaskDate = command.EditTask.EndTaskDate,
|
|
EndTaskTime = command.EditTask.EndTaskTime,
|
|
Id = command.EditTask.Id,
|
|
ReceiverId = command.EditTask.ReceiverId,
|
|
IsDone = command.EditTask.IsDone,
|
|
PositionId = command.EditTask.PositionId,
|
|
SenderId = command.EditTask.SenderId,
|
|
Title = command.EditTask.Title,
|
|
medias = command.EditTask.medias,
|
|
DeletedFileIds = command.EditTask.DeletedFileIds,
|
|
};
|
|
var result = _taskApplication.Edit(editCommand);
|
|
|
|
var res = result.IsSuccedded;
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = res,
|
|
message = result.Message,
|
|
});
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult OnGetEmployeeList()
|
|
{
|
|
var result = _accountApplication.GetAccountLowerPositionvalue();
|
|
|
|
|
|
|
|
return new JsonResult(new { result=result });
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|