Example #1
0
        public ActionResult SetLeave(int id)
        {
            var leaveType = _leaverepo.FindById(id);
            var employees = _userManager.GetUsersInRoleAsync("Employee").Result;

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