Exemple #1
0
        public async Task <ActionResult> SetLeave(int id)
        {
            var vacationtype = await _typerepo.FindById(id);

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

            foreach (var emp in employees)
            {
                var checkAllocation = await _allocationrepo.CheckAllocation(id, emp.Id);

                if (checkAllocation)
                {
                    continue;
                }
                var allocation = new VacationAllocationVM
                {
                    DateCreated    = DateTime.Now,
                    EmployeeId     = emp.Id,
                    VacationTypeId = id,
                    NumberOfDays   = vacationtype.Balance,
                    Period         = DateTime.Now.Year
                };
                var vacationallocation = _mapper.Map <VacationAllocation>(allocation);
                await _allocationrepo.Create(vacationallocation);
            }
            return(RedirectToAction(nameof(Index)));
        }
        public VacationAllocationVM Map(VacationAllocation allocation)
        {
            VacationAllocationVM obj = new VacationAllocationVM();

            obj.Id               = allocation.Id;
            obj.EmployeeId       = allocation.EmployeeId;
            obj.VacationTypeId   = allocation.VacationTypeId;
            obj.Used             = allocation.Used;
            obj.EmployeeName     = _db.Employees.Find(allocation.EmployeeId).fullname;
            obj.VacationTypeName = _db.VacationTypes.Find(allocation.VacationTypeId).Name;

            return(obj);
        }
        public List <VacationAllocationVM> Maplist(List <VacationAllocation> list)
        {
            List <VacationAllocationVM> alloc_list = new List <VacationAllocationVM>();

            for (int i = 0; i < list.Count(); i++)
            {
                VacationAllocationVM obj = new VacationAllocationVM();
                obj = Map(list[i]);
                alloc_list.Add(obj);
            }

            return(alloc_list);
        }