91 lines
4.2 KiB
C#
91 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using _0_Framework.Application;
|
|
using Company.Domain.InsuranceYearlySalaryAgg;
|
|
using CompanyManagment.App.Contracts.InsuranceYearlySalary;
|
|
|
|
namespace CompanyManagment.Application;
|
|
|
|
public class InsuranceYearlySalaryApplication : IInsuranceYearlySalaryApplication
|
|
{
|
|
private readonly IInsuranceYearlySalaryRepository _insuranceYearlySalaryRepository;
|
|
|
|
public InsuranceYearlySalaryApplication(IInsuranceYearlySalaryRepository insuranceYearlySalaryRepository)
|
|
{
|
|
_insuranceYearlySalaryRepository = insuranceYearlySalaryRepository;
|
|
}
|
|
|
|
public OperationResult Create(CreateInsuranceYearlySalary command)
|
|
{
|
|
var opreation = new OperationResult();
|
|
if (string.IsNullOrWhiteSpace(command.StartDateFa))
|
|
return opreation.Failed("تاریخ شروع را وارد کنید");
|
|
if (string.IsNullOrWhiteSpace(command.EndDateFa))
|
|
return opreation.Failed("تاریخ پایان وارد کنید");
|
|
|
|
var start = command.StartDateFa.ToGeorgianDateTime();
|
|
var end = command.EndDateFa.ToGeorgianDateTime();
|
|
int year = Convert.ToInt32(command.StartDateFa.Substring(0, 4));
|
|
int yearEnd = Convert.ToInt32(command.EndDateFa.Substring(0, 4));
|
|
|
|
|
|
if (year != yearEnd)
|
|
return opreation.Failed("تاریخ شروع و پایان باید در یک سال باشد");
|
|
if (_insuranceYearlySalaryRepository.Exists(x => x.Year == year))
|
|
return opreation.Failed("مزد های این سال قبلا وارد شده است");
|
|
|
|
|
|
var classiFiedSalary = new InsuranceYearlySalary(command.Group1, command.Group2, command.Group3, command.Group4,
|
|
command.Group5,
|
|
command.Group6, command.Group7, command.Group8, command.Group9, command.Group10, command.Group11,
|
|
command.Group12, command.Group13,
|
|
command.Group14, command.Group15, command.Group16, command.Group17, command.Group18, command.Group19,
|
|
command.Group20,
|
|
start, end, year, command.Group21, command.Group22, command.Group23, command.Group24, command.Group25, command.Group26,
|
|
command.Group27, command.Group28, command.Group29, command.Group30);
|
|
_insuranceYearlySalaryRepository.Create(classiFiedSalary);
|
|
_insuranceYearlySalaryRepository.SaveChanges();
|
|
return opreation.Succcedded();
|
|
}
|
|
|
|
public OperationResult Edit(EditInsuranceYearlySalary command)
|
|
{
|
|
var opreation = new OperationResult();
|
|
var res = _insuranceYearlySalaryRepository.Get(command.Id);
|
|
if (res == null)
|
|
return opreation.Failed("رکورد مورد نظر وجود ندارد");
|
|
|
|
res.Edit(command.Group1, command.Group2, command.Group3, command.Group4,
|
|
command.Group5,
|
|
command.Group6, command.Group7, command.Group8, command.Group9, command.Group10, command.Group11,
|
|
command.Group12, command.Group13,
|
|
command.Group14, command.Group15, command.Group16, command.Group17, command.Group18, command.Group19,
|
|
command.Group20, command.Group21, command.Group22, command.Group23, command.Group24, command.Group25, command.Group26,
|
|
command.Group27, command.Group28, command.Group29, command.Group30);
|
|
_insuranceYearlySalaryRepository.SaveChanges();
|
|
return opreation.Succcedded();
|
|
}
|
|
|
|
public EditInsuranceYearlySalary GetDetails(long id)
|
|
{
|
|
return _insuranceYearlySalaryRepository.GetDetails(id);
|
|
}
|
|
|
|
public List<InsuranceYearlySalaryViewModel> Search(InsuranceYearlySalarySearchModel searchModel)
|
|
{
|
|
return _insuranceYearlySalaryRepository.Search(searchModel);
|
|
}
|
|
|
|
public OperationResult RemoveClassifiedSalary(long id)
|
|
{
|
|
return _insuranceYearlySalaryRepository.RemoveClassifiedSalary(id);
|
|
}
|
|
|
|
public double GetBaseYearByDate(DateTime startDate, int years)
|
|
{
|
|
return _insuranceYearlySalaryRepository.GetBaseYearByDate(startDate, years);
|
|
}
|
|
} |