Example #1
0
        // GET: LeaveTypeController/Details/5
        public async Task <ActionResult> Details(int id)
        {
            var isExists = await _repo.isExists(id);

            if (!isExists)
            {
                return(NotFound());
            }

            var leaveType = await _repo.FindById(id);

            var model = _mapper.Map <LeaveTypeViewModel>(leaveType);

            return(View(model));
        }
        public async Task <ActionResult> SetLeave(int id)
        {
            var leavetype = await _leaverepo.FindById(id);

            var employees = _userManager.GetUsersInRoleAsync("Employee").Result;

            foreach (var emp in employees)
            {
                if (await _allocationrepo.CheckAllocation(id, emp.Id))
                {
                    continue;
                }

                var allocation = new LeaveAllocationViewModel
                {
                    DateCreated  = DateTime.Now,
                    EmployeeId   = emp.Id,
                    LeaveTypeId  = id,
                    NumberOfDays = leavetype.DefaultDays,
                    Period       = DateTime.Now.Year
                };
                var leaveallocation = _mapper.Map <LeaveAllocation>(allocation);
                await _allocationrepo.Create(leaveallocation);
            }
            return(RedirectToAction(nameof(Index)));
        }