public Task CreateAsync(TimeOffPolicyApproverDTO ItemDTO) { TimeOffPolicyApproversDTOChecker(ItemDTO); var Item = mapper.Map <TimeOffPolicyApproverDTO, TimeOffPolicyApprover>(ItemDTO); var Comparer = new TimeOffPolicyApproverComparer(); var template = unitOfWork.TimeOffPolicyApprovers.Find(x => x.EmployeePositionId == Item.EmployeePositionId && x.EmployeePositionTimeOffPolicyId == Item.EmployeePositionTimeOffPolicyId); if (template == null) { unitOfWork.TimeOffPolicyApprovers.Create(Item); return(unitOfWork.SaveAsync()); } else if (Comparer.Equals(template, Item)) { return(Task.CompletedTask); } else { throw new ArgumentException("Can not exist two Approvers with same Employee Position"); } }
public Task UpdateAsync(TimeOffPolicyApproverDTO ItemDTO) { TimeOffPolicyApproversDTOChecker(ItemDTO); var Item = mapper.Map <TimeOffPolicyApproverDTO, TimeOffPolicyApprover>(ItemDTO); var Comparer = new TimeOffPolicyApproverComparer(); if (unitOfWork.TimeOffPolicyApprovers.Get(Item.Id) is TimeOffPolicyApprover oldItem) { if (Comparer.Equals(oldItem, Item)) { return(Task.CompletedTask); } if (oldItem.EmployeePositionId != Item.EmployeePositionId || oldItem.EmployeePositionTimeOffPolicyId != Item.EmployeePositionTimeOffPolicyId) { return(CreateAsync(ItemDTO)); } } unitOfWork.TimeOffPolicyApprovers.Update(Item); return(unitOfWork.SaveAsync()); }