99 lines
3.1 KiB
C#
99 lines
3.1 KiB
C#
using _0_Framework.Application;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.InsuranceAgg;
|
|
using CompanyManagment.App.Contracts.Insurance;
|
|
using CompanyManagment.EFCore;
|
|
using System.Collections.Generic;
|
|
|
|
namespace CompanyManagment.Application;
|
|
|
|
public class InsuranceApplication : RepositoryBase<long, Insurance>, IInsuranceApplication
|
|
{
|
|
private readonly IInsuranceRepository _InsuranceRepository;
|
|
private readonly CompanyContext _context;
|
|
|
|
|
|
public InsuranceApplication(IInsuranceRepository insuranceRepository, CompanyContext context) : base(context)
|
|
{
|
|
_context = context;
|
|
_InsuranceRepository = insuranceRepository;
|
|
}
|
|
public OperationResult Create(CreateInsurance command)
|
|
{
|
|
var opration = new OperationResult();
|
|
if (_InsuranceRepository.Exists(x =>
|
|
x.Year == command.Year && x.Month == command.Month && x.WorkShopId == command.WorkShopId))
|
|
return opration.Failed("امکان ثبت رکورد تکراری وجود ندارد");
|
|
|
|
if (command.Year == 0)
|
|
{
|
|
return opration.Failed("لطفا سال را وارد کنید");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(command.Address))
|
|
{
|
|
return opration.Failed("آدرس را وارد کنید");
|
|
}
|
|
|
|
var Data = new Insurance(
|
|
command.Year,
|
|
command.Month,
|
|
command.EmployerStr,
|
|
command.WorkShopStr,
|
|
command.WorkShopId,
|
|
command.Address,
|
|
command.ListNumber);
|
|
|
|
_InsuranceRepository.Create(Data);
|
|
_InsuranceRepository.SaveChanges();
|
|
|
|
return opration.Succcedded();
|
|
|
|
}
|
|
public OperationResult Edit(EditInsurance command)
|
|
{
|
|
var opration = new OperationResult();
|
|
var insurance = _InsuranceRepository.Get(command.Id);
|
|
if (insurance == null)
|
|
return opration.Failed("رکورد مورد نظر یافت نشد");
|
|
|
|
if (command.Year == 0)
|
|
{
|
|
return opration.Failed("لطفا سال را وارد کنید");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(command.Address))
|
|
{
|
|
return opration.Failed("آدرس را وارد کنید");
|
|
}
|
|
|
|
insurance.Edit(
|
|
command.Year,
|
|
command.Month,
|
|
command.EmployerStr,
|
|
command.WorkShopStr,
|
|
command.WorkShopId,
|
|
command.Address,
|
|
command.ListNumber);
|
|
_InsuranceRepository.SaveChanges();
|
|
|
|
return opration.Succcedded();
|
|
}
|
|
public InsuranceViewModel GetDetails(long id)
|
|
{
|
|
return _InsuranceRepository.GetDetails(id);
|
|
}
|
|
public OperationResult Remove(long id)
|
|
{
|
|
var operation = new OperationResult();
|
|
|
|
_InsuranceRepository.Remove(id);
|
|
_InsuranceRepository.SaveChanges();
|
|
|
|
return operation.Succcedded(message:"بیمه با موفقیت حذف شد");
|
|
}
|
|
public IEnumerable<InsuranceViewModel> Search(InsuranceSearchModel searchModel)
|
|
{
|
|
return _InsuranceRepository.Search(searchModel);
|
|
}
|
|
} |