118 lines
4.7 KiB
C#
118 lines
4.7 KiB
C#
|
|
using System.Collections.Generic;
|
|
using _0_Framework.Application;
|
|
using Company.Domain.DateSalaryAgg;
|
|
using CompanyManagment.App.Contracts.DateSalary;
|
|
|
|
namespace CompanyManagment.Application;
|
|
|
|
public class DateSalaryApplication : IDateSalaryApplication
|
|
{
|
|
private readonly IDateSalaryRepository _dateSalaryRepository;
|
|
|
|
public DateSalaryApplication(IDateSalaryRepository dateSalaryRepository)
|
|
{
|
|
_dateSalaryRepository = dateSalaryRepository;
|
|
}
|
|
|
|
public OperationResult Create(CreateDateSalary command)
|
|
{
|
|
var startDate = command.StartDateFa.ToGeorgianDateTime();
|
|
var endDate = command.EndDateFa.ToGeorgianDateTime();
|
|
var operation = new OperationResult();
|
|
if (_dateSalaryRepository.Exists(x =>
|
|
( startDate >= x.StartDateGr && startDate <= x.EndDateGr )||(endDate >= x.StartDateGr && endDate <= x.EndDateGr)))
|
|
return operation.Failed(" بازه تاریخ وارد شده با رکوردهای قبلی تداخل دارد");
|
|
|
|
var dateSalary = new DateSalary(command.StartDateFa, command.EndDateFa);
|
|
_dateSalaryRepository.Create(dateSalary);
|
|
_dateSalaryRepository.SaveChanges();
|
|
|
|
return operation.Succcedded();
|
|
}
|
|
|
|
public OperationResult Edit(EditDateSalary command)
|
|
{
|
|
var startDate = command.StartDateFa.ToGeorgianDateTime();
|
|
var endDate = command.EndDateFa.ToGeorgianDateTime();
|
|
var operation = new OperationResult();
|
|
var dateSalaryEdit = _dateSalaryRepository.Get(command.Id);
|
|
if (dateSalaryEdit == null)
|
|
operation.Failed("رکورد مورد نظر وجود ندارد");
|
|
|
|
if (_dateSalaryRepository.Exists(x =>
|
|
(startDate >= x.StartDateGr && startDate <= x.EndDateGr && x.id != command.Id) || (endDate >= x.StartDateGr && endDate <= x.EndDateGr && x.id != command.Id)))
|
|
return operation.Failed(" بازه تاریخ وارد شده با رکوردهای قبلی تداخل دارد");
|
|
|
|
dateSalaryEdit.Edit(command.StartDateFa,command.EndDateFa);
|
|
_dateSalaryRepository.SaveChanges();
|
|
return operation.Succcedded(command.Id);
|
|
}
|
|
|
|
public EditDateSalary GetDetails(long id)
|
|
{
|
|
return _dateSalaryRepository.GetDetails(id);
|
|
}
|
|
|
|
public List<DateSalaryViewModel> Search(DateSalarySearchModel searchModel)
|
|
{
|
|
return _dateSalaryRepository.Search(searchModel);
|
|
}
|
|
|
|
public OperationResult CreateDateSalaryItemForInsuranceJob(CreateDateSalaryForInsuranceJob command)
|
|
{
|
|
var operation = new OperationResult();
|
|
var startDate = command.StartDateFa.ToGeorgianDateTime();
|
|
var endDate = command.EndDateFa.ToGeorgianDateTime();
|
|
if (_dateSalaryRepository.Exists(x => (startDate >= x.StartDateGr && startDate <= x.EndDateGr) || (endDate >= x.StartDateGr && endDate <= x.EndDateGr)))
|
|
return operation.Failed(" بازه تاریخ وارد شده با رکوردهای قبلی تداخل دارد");
|
|
bool result= _dateSalaryRepository.CreateDateSalaryItemForInsuranceJob(command);
|
|
if (result)
|
|
{
|
|
operation.IsSuccedded=true;
|
|
operation.Message="ثبت با موفقیت انجام شد";
|
|
}
|
|
else
|
|
{
|
|
operation.Failed("ثبت با خطا انجام شد");
|
|
}
|
|
return operation;
|
|
}
|
|
|
|
public OperationResult EditDateSalaryItemForInsuranceJob(CreateDateSalaryForInsuranceJob command)
|
|
{
|
|
var operation = new OperationResult();
|
|
var startDate = command.StartDateFa.ToGeorgianDateTime();
|
|
var endDate = command.EndDateFa.ToGeorgianDateTime();
|
|
if (_dateSalaryRepository.Exists(x => ((startDate >= x.StartDateGr && startDate <= x.EndDateGr) || (endDate >= x.StartDateGr && endDate <= x.EndDateGr)) && x.id != command.Id))
|
|
return operation.Failed(" بازه تاریخ وارد شده با رکوردهای قبلی تداخل دارد");
|
|
bool result = _dateSalaryRepository.EditDateSalaryItemForInsuranceJob(command);
|
|
if (result)
|
|
{
|
|
operation.IsSuccedded = true;
|
|
operation.Message = "ویرایش با موفقیت انجام شد";
|
|
}
|
|
else
|
|
{
|
|
operation.Failed("ویرایش با خطا انجام شد");
|
|
}
|
|
return operation;
|
|
}
|
|
|
|
public OperationResult Remove(long id)
|
|
{
|
|
var operation = new OperationResult();
|
|
|
|
bool result = _dateSalaryRepository.Remove(id);
|
|
if (result)
|
|
{
|
|
operation.IsSuccedded = true;
|
|
operation.Message = "حذف با موفقیت انجام شد";
|
|
}
|
|
else
|
|
{
|
|
operation.Failed("حذف با خطا انجام شد");
|
|
}
|
|
return operation;
|
|
}
|
|
} |