// GET: LeaveController/Details/5
        public ActionResult Details(int id)
        {
            if (!_repo.isExists(id))
            {
                return(NotFound());
            }
            var leaveType = _repo.FindById(id);
            var model     = _mapper.Map <LeaveTypeVM>(leaveType);

            return(View(model));
        }
Exemple #2
0
        public ActionResult SetLeave(int id)
        {
            var leaveType = _repoLeaveType.FindById(id);
            var people    = _people.GetUsersInRoleAsync("Member").Result;

            //int numUpdated = 0;

            foreach (var p in people)
            {
                if (_repo.CheckAllocation(id, p.Id))
                {
                    continue;   //continue means skip this record
                }
                // else create a new record
                var allocation = new LeaveAllocationVM
                {
                    DateCreated  = DateTime.Now,
                    PersonId     = p.Id,
                    LeaveTypeId  = id,
                    NumberOfDays = leaveType.DefaultDays,
                    Period       = DateTime.Now.Year
                };
                var leaveAllocation = _mapper.Map <LeaveAllocation>(allocation);
                _repo.Create(leaveAllocation);
            }
            return(RedirectToAction(nameof(Index)));
        }