public void DenyVacation(RequestProcessResultDTO result) { var vacation = _vacations.GetById(result.VacationID); var employee = _employees.GetById(result.EmployeeID); if (vacation != null) { using (TransactionScope scope = new TransactionScope()) { var transaction = new VacationsDAL.Entities.Transaction { BalanceChange = 0, Discription = result.Discription ?? Empty, EmployeeID = result.EmployeeID, TransactionDate = DateTime.UtcNow, TransactionTypeID = _transactionTypes.GetByType(TransactionTypeEnum.VacationDeny.ToString()).TransactionTypeID, TransactionID = Guid.NewGuid().ToString() }; _transactions.Add(transaction); vacation.VacationStatusTypeID = _vacationStatusTypes.GetByType(VacationStatusTypeEnum.Denied.ToString()).VacationStatusTypeID; vacation.ProcessedByID = ReviewerID; vacation.TransactionID = transaction.TransactionID; _vacations.Update(vacation); _emailService.SendAsync(employee.WorkEmail, $"{employee.Name} {employee.Surname}", "Vacation request.", "Your vacation request was denied.", $"{employee.Name} {employee.Surname}, your vacation request from {vacation.DateOfBegin.ToString("dd-MM-yyyy")} to {vacation.DateOfEnd.ToString("dd-MM-yyyy")} was denied. Please, check it."); scope.Complete(); } } }
public void UpdateEmployeeBalance(EmployeeDTO employee, string comment) { using (TransactionScope scope = new TransactionScope()) { var employeeToUpdate = _employees.GetById(employee.EmployeeID); var transaction = new VacationsDAL.Entities.Transaction { BalanceChange = employee.VacationBalance-employeeToUpdate.VacationBalance, Discription = comment, EmployeeID = employeeToUpdate.EmployeeID, TransactionDate = DateTime.UtcNow, TransactionTypeID = _transactionTypes.GetByType(TransactionTypeEnum.ForceBalanceChangeTransaction.ToString()).TransactionTypeID, TransactionID = Guid.NewGuid().ToString() }; employeeToUpdate.VacationBalance = employee.VacationBalance; _employees.Update(); _transactions.Add(transaction); scope.Complete(); } }