Example #1
0
        public async Task <ActionResult> SetLeave(int id)
        {
            var varLeaveType = await _ILeaveTypeRepository.FindByID(id);

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

            int intCounter = 0;

            foreach (var forEmployee in varEmployees)
            {
                if (!await _ILeaveAllocationRepository.checkLeaveAllocated(forEmployee.Id, id, DateTime.Now.Year))
                {
                    intCounter++;
                    LeaveAllocationVMClass locLeaveAllocationVMClass = new LeaveAllocationVMClass
                    {
                        NumberOfDays = varLeaveType.DefaultDays,
                        DateCreated  = DateTime.Now,
                        EmployeeID   = forEmployee.Id,
                        LeaveTypeID  = id,
                        Period       = DateTime.Now.Year
                    };

                    var varLeaveAllocationMap = _IMapper.Map <LeaveAllocation>(locLeaveAllocationVMClass);
                    await _ILeaveAllocationRepository.Create(varLeaveAllocationMap);
                }
            }

            CreateLeaveAllocationVMClass locCreateLeaveAllocationVMClass = new CreateLeaveAllocationVMClass
            {
                NumberUpdated = intCounter
            };

            return(View(locCreateLeaveAllocationVMClass));
        }