示例#1
0
        public async Task <ActionResult> SetLeave(int id)
        {
            var leaveType = await _leaveTypeRepo.FindById(id);

            var employee = await _userManager.GetUsersInRoleAsync("Employee");

            foreach (var emp in employee)
            {
                if (await _leaveAllocationRepo.isLeaveExiss(id, emp.Id))
                {
                    continue;
                }
                var allocation = new LeaveAllocationVM
                {
                    DateCreated  = DateTime.Now,
                    EmployeeId   = emp.Id,
                    leaveId      = id,
                    NumberOfDays = leaveType.DefaultDays,
                    Period       = DateTime.Now.Year
                };
                var leaveAllocation = _mapper.Map <LeaveAllocation>(allocation);
                await _leaveAllocationRepo.Create(leaveAllocation);
            }
            return(RedirectToAction(nameof(Index)));
        }