add new metods
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using _0_Framework.Application;
|
||||
using _0_Framework.Domain;
|
||||
using CompanyManagment.App.Contracts.InsuranceJob;
|
||||
using CompanyManagment.App.Contracts.InsuranceJobItem;
|
||||
|
||||
namespace Company.Domain.InsurancJobAgg;
|
||||
|
||||
@@ -17,6 +18,9 @@ public interface IInsuranceJobRepositpry:IRepository<long, InsuranceJob>
|
||||
List<InsuranceJobViewModel> GetInsurancJob();
|
||||
List<InsuranceJobViewModel> Search(InsuranceJobSearchModel searchModel);
|
||||
OperationResult CreateInsuranceJob(CreateInsuranceJob command);
|
||||
List<(long id, string date)> GetOldYersInsuranceItemIds();
|
||||
OperationResult CopyFromLastYear(string startDate, string endDate, long insuranceJobItem);
|
||||
OperationResult Remove(long id);
|
||||
OperationResult EditInsuranceJob(EditInsuranceJob command);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using CompanyManagment.App.Contracts.InsuranceJobItem;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.InsuranceJob;
|
||||
|
||||
public class CopyFromLastYearViewModel
|
||||
{
|
||||
public string StartDate { get; set; }
|
||||
public string EndDate { get; set; }
|
||||
|
||||
public long InsuranceJobItemId { get; set; }
|
||||
|
||||
public List<(long id, string date)> InsuranceJobItemViewModels { get; set; }
|
||||
}
|
||||
@@ -10,6 +10,8 @@ namespace CompanyManagment.App.Contracts.InsuranceJob;
|
||||
|
||||
public interface IInsuranceJobApplication
|
||||
{
|
||||
List<(long id, string date)> GetOldYersInsuranceItemIds();
|
||||
OperationResult CopyFromLastYear(string startDate, string endDate, long insuranceJobItem);
|
||||
OperationResult Create(CreateInsuranceJob command);
|
||||
OperationResult Edit(EditInsuranceJob command);
|
||||
EditInsuranceJob GetDetails(long id);
|
||||
|
||||
@@ -19,6 +19,16 @@ public class InsuranceJobApplication: IInsuranceJobApplication
|
||||
_insuranceJobItemRepositpry = insuranceJobItemRepositpry;
|
||||
}
|
||||
|
||||
public List<(long id, string date)> GetOldYersInsuranceItemIds()
|
||||
{
|
||||
return _insuranceJobRepositpry.GetOldYersInsuranceItemIds();
|
||||
}
|
||||
|
||||
public OperationResult CopyFromLastYear(string startDate, string endDate, long insuranceJobItem)
|
||||
{
|
||||
return _insuranceJobRepositpry.CopyFromLastYear(startDate, endDate, insuranceJobItem);
|
||||
}
|
||||
|
||||
public OperationResult Create(CreateInsuranceJob command)
|
||||
{
|
||||
var opration = new OperationResult();
|
||||
|
||||
@@ -8,7 +8,9 @@ using Company.Domain.InsuranceJobItemAgg;
|
||||
using Company.Domain.InsurancJobAgg;
|
||||
using Company.Domain.PercentageAgg;
|
||||
using CompanyManagment.App.Contracts.InsuranceJob;
|
||||
using CompanyManagment.App.Contracts.InsuranceJobItem;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
|
||||
|
||||
|
||||
namespace CompanyManagment.EFCore.Repository;
|
||||
@@ -129,6 +131,101 @@ public class InsuranceJobRepository : RepositoryBase<long, InsuranceJob>, IInsur
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<(long id, string date)> GetOldYersInsuranceItemIds()
|
||||
{
|
||||
var res = _context.InsuranceJobItems
|
||||
.GroupBy(x => x.StartDate)
|
||||
.Select(g => g.First())
|
||||
.Select(x=> new InsuranceJobItemViewModel()
|
||||
{
|
||||
Id = x.id,
|
||||
StartDate = x.StartDate,
|
||||
EndDate = x.EndDate,
|
||||
|
||||
|
||||
})
|
||||
.ToList();
|
||||
return res.Select(x=> (x.Id, $"{(x.StartDate.HasValue ? x.StartDate.Value.ToFarsi() : "نامشخص")} - {(x.EndDate.HasValue ? x.EndDate.Value.ToFarsi() : "نامشخص")}")).ToList();
|
||||
|
||||
}
|
||||
|
||||
public OperationResult CopyFromLastYear(string startDate, string endDate, long insuranceJobItem)
|
||||
{
|
||||
var op = new OperationResult();
|
||||
DateTime startDateGr = new DateTime();
|
||||
DateTime endDateGr = new DateTime();
|
||||
try
|
||||
{
|
||||
startDateGr = startDate.ToGeorgianDateTime();
|
||||
endDateGr = endDate.ToGeorgianDateTime();
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return op.Failed("تاریخ به درستی وارد نشده است");
|
||||
|
||||
}
|
||||
|
||||
|
||||
var chekExist = _insuranceJobItemRepositpry.Exists(x => x.StartDate < endDateGr && x.EndDate > startDateGr);
|
||||
if (chekExist)
|
||||
return op.Failed("بازه تاریخ وارد شده با بازه های قبلی تداخل دارد");
|
||||
|
||||
var insuranceJobItemObj = _insuranceJobItemRepositpry.Get(insuranceJobItem);
|
||||
if (insuranceJobItemObj == null)
|
||||
return op.Failed("آیتم شغلی انتخاب شده وجود ندارد");
|
||||
var insuranceJobItemList = _context.InsuranceJobItems.Where(x => x.StartDate == insuranceJobItemObj.StartDate).Select(x => new InsuranceJobItemViewModel()
|
||||
{
|
||||
PercentageLessThan = 0,
|
||||
PercentageMoreThan = 0,
|
||||
InsuranceJobId = insuranceJobItemObj.InsuranceJobId,
|
||||
StartDate = startDateGr,
|
||||
EndDate = endDateGr,
|
||||
});
|
||||
|
||||
if (!insuranceJobItemList.Any())
|
||||
return op.Failed("خطا");
|
||||
|
||||
|
||||
using (var transaction = _context.Database.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
foreach (var item in insuranceJobItemList)
|
||||
{
|
||||
|
||||
_insuranceJobItemRepositpry.CreateInsuranceJobItem(item);
|
||||
|
||||
if (!_percentageRepository.Exists(x => x.Percent == item.PercentageLessThan))
|
||||
{
|
||||
var percentage = new Percentage(item.PercentageLessThan);
|
||||
_percentageRepository.Create(percentage);
|
||||
}
|
||||
|
||||
if (!_percentageRepository.Exists(x => x.Percent == item.PercentageMoreThan))
|
||||
{
|
||||
var percentage2 = new Percentage(item.PercentageMoreThan);
|
||||
_percentageRepository.Create(percentage2);
|
||||
}
|
||||
|
||||
_percentageRepository.SaveChanges();
|
||||
}
|
||||
// SaveChanges();
|
||||
transaction.Commit();
|
||||
op.IsSuccedded = true;
|
||||
op.Message = "ثبت اطلاعات با موفقیت انجام شد";
|
||||
return op;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return op.Failed("ثبت اطلاعات با خطا مواجه شد");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public OperationResult Remove(long id)
|
||||
{
|
||||
OperationResult result = new OperationResult();
|
||||
|
||||
@@ -57,6 +57,20 @@ public class IndexModel : PageModel
|
||||
return new JsonResult(result);
|
||||
}
|
||||
|
||||
public IActionResult OnGetCopyFromLastYear()
|
||||
{
|
||||
|
||||
var model = new CopyFromLastYearViewModel()
|
||||
{
|
||||
InsuranceJobItemViewModels = _insuranceJobApplication.GetOldYersInsuranceItemIds()
|
||||
};
|
||||
return new JsonResult(new { });
|
||||
}
|
||||
public IActionResult OnPostCopyFromLastYear(string startDate, string endDate, long insuranceJobItemId)
|
||||
{
|
||||
return new JsonResult(new { });
|
||||
}
|
||||
|
||||
//public async Task<IActionResult> OnPostJobListByText(string textSearch)
|
||||
//{
|
||||
// var jobs = _jobApplication.GetJobListByText(textSearch);
|
||||
|
||||
Reference in New Issue
Block a user