Files
Backend-Api/CompanyManagment.Application/EmployeeComputeOptionsApplication.cs

66 lines
2.4 KiB
C#

using CompanyManagment.App.Contracts.EmployeeComputeOptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using _0_Framework.Application;
using Company.Domain.EmployeeComputeOptionsAgg;
using Company.Domain.EmployeeAgg;
namespace CompanyManagment.Application;
public class EmployeeComputeOptionsApplication : IEmployeeComputeOptionsApplication
{
private readonly IEmployeeComputeOptionsRepository _employeeComputeOptionsRepository;
public EmployeeComputeOptionsApplication(IEmployeeComputeOptionsRepository employeeComputeOptionsRepository)
{
_employeeComputeOptionsRepository = employeeComputeOptionsRepository;
}
public OperationResult Create(CreateEmployeeComputeOptions command)
{
var opration = new OperationResult();
try
{
if (_employeeComputeOptionsRepository.Exists(x =>
x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId))
{
var query = GetEmployeeOptions(command.WorkshopId, command.EmployeeId);
var editOptions = _employeeComputeOptionsRepository.Get(query.Id);
editOptions.Edit(command.ComputeOptions, command.BonusesOptions, command.YearsOptions,
command.CreateContract, command.SignContract, command.CreateCheckout, command.SignCheckout);
_employeeComputeOptionsRepository.SaveChanges();
return opration.Succcedded();
}
else
{
var createOptions = new EmployeeComputeOptions(command.WorkshopId, command.EmployeeId,
command.ComputeOptions, command.BonusesOptions, command.YearsOptions, command.CreateContract,
command.SignContract, command.CreateCheckout, command.SignCheckout);
_employeeComputeOptionsRepository.Create(createOptions);
_employeeComputeOptionsRepository.SaveChanges();
return opration.Succcedded();
}
}
catch (Exception a)
{
return opration.Failed("ثبت با خطا مواجه شد");
}
}
public EmployeeComputeOptionsViewModel GetEmployeeOptions(long workshopId, long employeeId)
{
return _employeeComputeOptionsRepository.GetEmployeeOptions(workshopId, employeeId);
}
public List<EmployeeComputeOptionsViewModel> GetAllByWorkshopId(long workshopId)
{
return _employeeComputeOptionsRepository.GetAllByWorkshopId(workshopId);
}
}