diff --git a/Company.Domain/SmsResultAgg/ISmsSettingsRepository.cs b/Company.Domain/SmsResultAgg/ISmsSettingsRepository.cs index a2c864a5..8baacff0 100644 --- a/Company.Domain/SmsResultAgg/ISmsSettingsRepository.cs +++ b/Company.Domain/SmsResultAgg/ISmsSettingsRepository.cs @@ -1,6 +1,7 @@ using _0_Framework.Application.Enums; using _0_Framework.Domain; using CompanyManagment.App.Contracts.SmsResult; +using System.Collections.Generic; using System.Threading.Tasks; namespace Company.Domain.SmsResultAgg; @@ -27,4 +28,25 @@ public interface ISmsSettingsRepository : IRepository /// /// Task RemoveItem(long id); + + + #region ForApi + + /// + /// دریافت لیست پیامک های خودکار بر اساس نوع آن + /// Api + /// + /// + /// + Task> GetSmsSettingList(TypeOfSmsSetting typeOfSmsSetting); + + + + /// + /// دریافت اطلاعات تنظیمات پیامک جهت ویرایش + /// + /// + /// + Task GetSmsSettingDataToEdit(long id); + #endregion } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/SmsResult/CreateSmsSetting.cs b/CompanyManagment.App.Contracts/SmsResult/CreateSmsSetting.cs index f467ca34..7969c381 100644 --- a/CompanyManagment.App.Contracts/SmsResult/CreateSmsSetting.cs +++ b/CompanyManagment.App.Contracts/SmsResult/CreateSmsSetting.cs @@ -60,3 +60,29 @@ public class SmsSettingViewModel /// public List EditSmsSettings { get; set; } } + + + +/// +/// لیست تنظیمات پیامک خودکار +/// +public class SmsSettingDto +{ + /// + /// آی دی + /// + public long Id { get; set; } + + /// + /// عدد روز از ماه + /// + public int DayOfMonth { get; set; } + + /// + /// نمایش ساعت و دقیقه + /// + public string TimeOfDayDisplay { get; set; } +} + + + diff --git a/CompanyManagment.App.Contracts/SmsResult/ISmsSettingApplication.cs b/CompanyManagment.App.Contracts/SmsResult/ISmsSettingApplication.cs index 49fdc4e8..813d7540 100644 --- a/CompanyManagment.App.Contracts/SmsResult/ISmsSettingApplication.cs +++ b/CompanyManagment.App.Contracts/SmsResult/ISmsSettingApplication.cs @@ -75,4 +75,31 @@ public interface ISmsSettingApplication /// /// Task InstantSendBlockSms(List command); + + + #region ForApi + + /// + /// دریافت لیست پیامک های خودکار بر اساس نوع آن + /// Api + /// + /// + /// + Task> GetSmsSettingList(TypeOfSmsSetting typeOfSmsSetting); + + /// + /// دریافت اطلاعات تنظیمات پیامک جهت ویرایش + /// + /// + /// + Task GetSmsSettingDataToEdit(long id); + + /// + /// ویرایش تنظیمات پیامک + /// + /// + /// + Task EditSmsSetting(SmsSettingDto command); + + #endregion } \ No newline at end of file diff --git a/CompanyManagment.Application/SmsSettingApplication.cs b/CompanyManagment.Application/SmsSettingApplication.cs index 203a9e23..37894b2e 100644 --- a/CompanyManagment.Application/SmsSettingApplication.cs +++ b/CompanyManagment.Application/SmsSettingApplication.cs @@ -165,4 +165,57 @@ public class SmsSettingApplication : ISmsSettingApplication return op.Failed("موردی انتخاب نشده است"); } } + + #region ForApi + + /// + /// دریافت لیست پیامک های خودکار بر اساس نوع آن + /// Api + /// + /// + /// + public async Task> GetSmsSettingList(TypeOfSmsSetting typeOfSmsSetting) + { + return await _smsSettingsRepository.GetSmsSettingList(typeOfSmsSetting); + } + + + public async Task GetSmsSettingDataToEdit(long id) + { + return await _smsSettingsRepository.GetSmsSettingDataToEdit(id); + } + + + public async Task EditSmsSetting(SmsSettingDto command) + { + var op = new OperationResult(); + var editSmsSetting = _smsSettingsRepository.Get(command.Id); + var timeSpan = new TimeSpan(); + if (string.IsNullOrWhiteSpace(command.TimeOfDayDisplay)) + return op.Failed("ساعت وارد نشده است"); + + try + { + timeSpan = TimeSpan.ParseExact(command.TimeOfDayDisplay, @"hh\:mm", null); + } + catch (Exception e) + { + return op.Failed("فرمت ساعت اشتباه است"); + } + + if (command.DayOfMonth < 1 || command.DayOfMonth > 31) + { + return op.Failed("عدد روز می بایست بین 1 تا 31 باشد"); + } + + if (_smsSettingsRepository.Exists(x => x.DayOfMonth == command.DayOfMonth && x.TimeOfDay == timeSpan && x.TypeOfSmsSetting == editSmsSetting.TypeOfSmsSetting && x.id != command.Id)) + return op.Failed("رکورد ایجاد شده تکراری است"); + + + editSmsSetting.Edit(command.DayOfMonth, timeSpan); + await _smsSettingsRepository.SaveChangesAsync(); + + return op.Succcedded(); + } + #endregion } \ No newline at end of file diff --git a/CompanyManagment.EFCore/Repository/SmsSettingsRepository.cs b/CompanyManagment.EFCore/Repository/SmsSettingsRepository.cs index d0922b29..da3c11b3 100644 --- a/CompanyManagment.EFCore/Repository/SmsSettingsRepository.cs +++ b/CompanyManagment.EFCore/Repository/SmsSettingsRepository.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using _0_Framework.Application.Enums; using _0_Framework.InfraStructure; @@ -68,4 +69,48 @@ public class SmsSettingsRepository : RepositoryBase, ISmsSetti _context.SmsSettings.Remove(removeItem); await _context.SaveChangesAsync(); } + + + #region ForApi + /// + /// دریافت لیست پیامک های خودکار بر اساس نوع آن + /// Api + /// + /// + /// + public async Task> GetSmsSettingList(TypeOfSmsSetting typeOfSmsSetting) + { + + var data = await _context.SmsSettings + .Where(x => x.TypeOfSmsSetting == typeOfSmsSetting) + .OrderBy(x => x.DayOfMonth).ThenBy(x => x.TimeOfDay) + .Select(x => + new SmsSettingDto() + { + Id = x.id, + DayOfMonth = x.DayOfMonth, + TimeOfDayDisplay = x.TimeOfDay.ToString(@"hh\:mm") + }).ToListAsync(); + + return data; + } + + public async Task GetSmsSettingDataToEdit(long id) + { + var edit = new SmsSettingDto(); + var getItem = await _context.SmsSettings.FirstOrDefaultAsync(x => x.id == id); + + if (getItem != null) + { + edit.Id = getItem.id; + edit.TimeOfDayDisplay = getItem.TimeOfDay.ToString(@"hh\:mm"); + edit.DayOfMonth = getItem.DayOfMonth; + + } + + return edit; + } + + + #endregion } \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Controllers/SmsReportController.cs b/ServiceHost/Areas/Admin/Controllers/SmsReportController.cs index 254d5d05..0e932d10 100644 --- a/ServiceHost/Areas/Admin/Controllers/SmsReportController.cs +++ b/ServiceHost/Areas/Admin/Controllers/SmsReportController.cs @@ -1,4 +1,6 @@ -using _0_Framework.Application.Sms; +using _0_Framework.Application; +using _0_Framework.Application.Enums; +using _0_Framework.Application.Sms; using CompanyManagment.App.Contracts.SmsResult; using CompanyManagment.App.Contracts.SmsResult.Dto; using Microsoft.AspNetCore.Mvc; @@ -9,12 +11,14 @@ namespace ServiceHost.Areas.Admin.Controllers; public class SmsReportController : AdminBaseController { private readonly ISmsResultApplication _smsResultApplication; + private readonly ISmsSettingApplication _smsSettingApplication; private readonly ISmsService _smsService; - public SmsReportController(ISmsResultApplication smsResultApplication, ISmsService smsService) + public SmsReportController(ISmsResultApplication smsResultApplication, ISmsService smsService, ISmsSettingApplication smsSettingApplication) { _smsResultApplication = smsResultApplication; _smsService = smsService; + _smsSettingApplication = smsSettingApplication; } /// @@ -56,4 +60,171 @@ public class SmsReportController : AdminBaseController return result; } + //تنظیمات پیامک خودکار + #region SmsSettings + + /// + /// لیست تنظیمات پیامک - یادآور + /// + /// + [HttpGet("ReminderSmsSettingList")] + public async Task> ReminderSmsSettingList() + { + var result = await _smsSettingApplication.GetSmsSettingList(TypeOfSmsSetting.InstitutionContractDebtReminder); + return result; + } + + + /// + /// لیست تنظیمات پیامک - مسدودی + /// + /// + [HttpGet("BlockSmsSettingList")] + public async Task> BlockSmsSettingList() + { + var result = await _smsSettingApplication.GetSmsSettingList(TypeOfSmsSetting.BlockContractingParty); + return result; + } + + /// + /// لیست تنظیمات پیامک - هشدار قضایی + /// + /// + [HttpGet("WarningSmsSettingList")] + public async Task> WarningSmsSettingList() + { + var result = await _smsSettingApplication.GetSmsSettingList(TypeOfSmsSetting.Warning); + return result; + } + + + /// + /// لیست تنظیمات پیامک - اقدام قضایی + /// + /// + [HttpGet("LegalActionSmsSettingList")] + public async Task> LegalActionSmsSettingList() + { + var result = await _smsSettingApplication.GetSmsSettingList(TypeOfSmsSetting.LegalAction); + return result; + } + + /// + /// لیست تنظیمات پیامک - تایید قراداد مالی + /// + /// + [HttpGet("ContractConfirmSmsSettingList")] + public async Task> ContractConfirmSmsSettingList() + { + var result = await _smsSettingApplication.GetSmsSettingList(TypeOfSmsSetting.InstitutionContractConfirm); + return result; + } + + //=====================Create========================= + + /// + /// ایجاد پیامک یادآور + /// + /// + /// + /// + /// + [HttpPost("CreateReminderSmsSetting")] + public async Task> CreateReminderSmsSetting(int dayOfMonth, string timeOfDay) + { + var result = await _smsSettingApplication.CreateSmsSetting(dayOfMonth, timeOfDay, TypeOfSmsSetting.InstitutionContractDebtReminder); + return result; + } + + /// + /// ایجاد پیامک مسدودی + /// + /// + /// + /// + [HttpPost("CreateBlockSmsSetting")] + public async Task> CreateBlockSmsSetting(int dayOfMonth, string timeOfDay) + { + var result = await _smsSettingApplication.CreateSmsSetting(dayOfMonth, timeOfDay, TypeOfSmsSetting.BlockContractingParty); + return result; + } + + /// + /// ایجاد پیامک هشدار قضایی + /// + /// + /// + /// + [HttpPost("CreateWarningSmsSetting")] + public async Task> CreateWarningSmsSetting(int dayOfMonth, string timeOfDay) + { + var result = await _smsSettingApplication.CreateSmsSetting(dayOfMonth, timeOfDay, TypeOfSmsSetting.Warning); + return result; + } + + + /// + /// ایجاد پیامک اقدام قضایی + /// + /// + /// + /// + [HttpPost("CreateLegalActionSmsSetting")] + public async Task> CreateLegalActionSmsSetting(int dayOfMonth, string timeOfDay) + { + var result = await _smsSettingApplication.CreateSmsSetting(dayOfMonth, timeOfDay, TypeOfSmsSetting.LegalAction); + return result; + } + + + /// + /// ایجاد پیامک تایید قرارداد مالی + /// + /// + /// + /// + [HttpPost("CreateContractConfirmSmsSetting")] + public async Task> CreateContractConfirmSmsSetting(int dayOfMonth, string timeOfDay) + { + var result = await _smsSettingApplication.CreateSmsSetting(dayOfMonth, timeOfDay, TypeOfSmsSetting.InstitutionContractConfirm); + return result; + } + //=====================Edit========================= + + /// + /// دریافت اطلاعات ویرایش تنظیمات پیامک + /// + /// + /// + [HttpGet("GetEditData")] + public async Task GetEditData(long id) + { + return await _smsSettingApplication.GetSmsSettingDataToEdit(id); + } + + /// + /// ویرایش تنظیمات پیامک + /// + /// + /// + [HttpPost("EditSmsSetting")] + public async Task> EditSmsSetting(SmsSettingDto command) + { + var result =await _smsSettingApplication.EditSmsSetting(command); + return result; + } + + //=====================Remove========================= + + /// + /// حذف تنظیمات پیامک + /// + /// + /// + [HttpDelete] + public async Task RemoveSmsSetting(long id) + { + await _smsSettingApplication.RemoveSetting(id); + } + #endregion } \ No newline at end of file