87 lines
3.6 KiB
C#
87 lines
3.6 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.ClassifiedSalaryAgg;
|
|
using CompanyManagment.App.Contracts.ClassifiedSalary;
|
|
|
|
namespace CompanyManagment.Application;
|
|
|
|
public class ClassifiedSalaryApplication : IClassifiedSalaryApplication
|
|
|
|
{
|
|
private readonly IClassifiedSalaryRepository _classifiedSalaryRepository;
|
|
|
|
public ClassifiedSalaryApplication(IClassifiedSalaryRepository classifiedSalaryRepository)
|
|
{
|
|
_classifiedSalaryRepository = classifiedSalaryRepository;
|
|
}
|
|
|
|
public OperationResult Create(CreateClassifiedSalary 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 (_classifiedSalaryRepository.Exists(x => x.Year == year))
|
|
return opreation.Failed("مزد های این سال قبلا وارد شده است");
|
|
|
|
|
|
var classiFiedSalary = new ClassifiedSalary(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);
|
|
_classifiedSalaryRepository.Create(classiFiedSalary);
|
|
_classifiedSalaryRepository.SaveChanges();
|
|
return opreation.Succcedded();
|
|
|
|
|
|
}
|
|
|
|
public OperationResult Edit(EditClassifiedSalary command)
|
|
{
|
|
var opreation = new OperationResult();
|
|
var res = _classifiedSalaryRepository.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);
|
|
_classifiedSalaryRepository.SaveChanges();
|
|
return opreation.Succcedded();
|
|
}
|
|
|
|
public EditClassifiedSalary GetDetails(long id)
|
|
{
|
|
return _classifiedSalaryRepository.GetDetails(id);
|
|
}
|
|
|
|
public List<ClassifiedSalaryViewMode> Search(ClassifiedSalarySearchModel searchModel)
|
|
{
|
|
return _classifiedSalaryRepository.Search(searchModel);
|
|
}
|
|
|
|
public OperationResult RemoveClassifiedSalary(long id)
|
|
{
|
|
return _classifiedSalaryRepository.RemoveClassifiedSalary(id);
|
|
}
|
|
} |