53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using _0_Framework.Application;
|
|
using Company.Domain.RewardAgg;
|
|
using CompanyManagment.App.Contracts.Reward;
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
|
|
namespace CompanyManagment.Application;
|
|
|
|
public class RewardApplication : IRewardApplication
|
|
{
|
|
private readonly IRewardRepository _rewardRepository;
|
|
private readonly IAuthHelper _authHelper;
|
|
|
|
public RewardApplication(IRewardRepository rewardRepository, IAuthHelper authHelper)
|
|
{
|
|
_rewardRepository = rewardRepository;
|
|
_authHelper = authHelper;
|
|
}
|
|
|
|
public List<RewardSearchViewModel> GetSearchList(RewardSearchViewModel searchModel)
|
|
{
|
|
return _rewardRepository.GetSearchList(searchModel);
|
|
}
|
|
|
|
public EditRewardViewModel GetDetails(long id)
|
|
{
|
|
return _rewardRepository.GetDetails(id);
|
|
}
|
|
|
|
public OperationResult Create(CreateRewardViewModel command)
|
|
{
|
|
var op = new OperationResult();
|
|
foreach (var employeeId in command.EmployeeIds)
|
|
{
|
|
var entity = new Reward(employeeId, command.WorkshopId, command.Amount, command.Description, command.RewardedByAccountId);
|
|
_rewardRepository.Create(entity);
|
|
}
|
|
|
|
_rewardRepository.SaveChanges();
|
|
return op.Succcedded();
|
|
}
|
|
|
|
public OperationResult Edit(EditRewardViewModel command)
|
|
{
|
|
var op = new OperationResult();
|
|
var entity = _rewardRepository.Get(command.Id);
|
|
if (entity == null)
|
|
return op.Failed("چنین آیتمی وجود ندارد");
|
|
entity.Edit(command.Amount,command.Description,command.RewardedByAccountId);
|
|
_rewardRepository.SaveChanges();
|
|
return op.Succcedded(entity.id);
|
|
}
|
|
} |