64 lines
1.6 KiB
C#
64 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using Company.Domain.PercentageAgg;
|
|
using CompanyManagment.App.Contracts.Percentage;
|
|
|
|
namespace CompanyManagment.Application;
|
|
|
|
public class PercentageApplication : IPercentageApplication
|
|
{
|
|
private readonly IPercentageRepository _percentageRepository;
|
|
|
|
public PercentageApplication(IPercentageRepository percentageRepository)
|
|
{
|
|
_percentageRepository = percentageRepository;
|
|
}
|
|
|
|
public void Create(CreatePercentage command)
|
|
{
|
|
if (command.Percent > 0)
|
|
{
|
|
if (_percentageRepository.Exists(x => x.Percent == command.Percent))
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
var percentage = new Percentage(command.Percent);
|
|
_percentageRepository.Create(percentage);
|
|
_percentageRepository.SaveChanges();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
public void Edit(EditPercentage command)
|
|
{
|
|
|
|
var percentageEdit = _percentageRepository.Get(command.Id);
|
|
if (percentageEdit != null)
|
|
{
|
|
if (_percentageRepository.Exists(x => x.Percent == command.Percent && x.id != command.Id))
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
percentageEdit.Edit(command.Percent);
|
|
_percentageRepository.SaveChanges();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public EditPercentage GetDetails(long id)
|
|
{
|
|
return _percentageRepository.GetDetails(id);
|
|
}
|
|
|
|
public List<PercentageViewModel> Search(PercentageSearchModel searchModel)
|
|
{
|
|
return _percentageRepository.Search(searchModel);
|
|
}
|
|
} |