public async Task Execute(CreateGlobalLimitOperationRequest request) { var currentEmployee = await _authorizationContext.CurrentEmployee(); if (!currentEmployee.IsTopLevelManager) { throw new ApplicationException("Cannot create a global limit, as you're not authorized to do so."); } var allEmployees = await _employeeRepository.ListAsync(); var oldLimitsToDelete = await _limitRepository.ListAsync(); var globalLimit = new Domain.Entity.LearningCalendar.Limit { Id = new Guid(), DaysPerQuarter = request.DaysPerQuarter }; await _limitRepository.CreateAsync(globalLimit); foreach (var employee in allEmployees) { employee.LimitId = globalLimit.Id; } await _employeeRepository.UpdateAsync(allEmployees); await _limitRepository.DeleteAsync(oldLimitsToDelete); }
public async Task Execute(CreateLimitOperationRequest request) { var targetEmployee = (await _authorizationContext.CurrentEmployee()) .ManagedTeam.Employees .FirstOrDefault(employee => employee.Id == request.EmployeeId); if (targetEmployee == null) { throw new ApplicationException("You can only create limits for your direct subordinates"); } targetEmployee = await _employeeRepository.QuerySingleAsync(employee => employee.Id == request.EmployeeId); targetEmployee.Limit = new Domain.Entity.LearningCalendar.Limit { DaysPerQuarter = request.DaysPerQuarter }; await _employeeRepository.UpdateAsync(targetEmployee); var nonAssignedLimits = await _limitRepository.GetNonAssignedLimitsAsync(); await _limitRepository.DeleteAsync(nonAssignedLimits); }