Beispiel #1
0
        // GET: LeaveTypes/Details/5
        public ActionResult Details(int id)
        {
            var leaveType = _repo.FindById(id);
            var model     = _mapper.Map <LeaveTypeVM>(leaveType);

            return(View(model));
        }
        // GET: LeaveTypesController/Details/5
        public ActionResult Details(int id)
        {
            if (!_repo.isExists(id))
            {
                return(NotFound());
            }

            return(View(_mapper.Map <LeaveTypeVM>(_repo.FindById(id))));
        }
        // GET: LeaveTypesController/Details/5
        public async Task <ActionResult> Details(int id)
        {
            if (!(await _repo.Exists(id)))
            {
                return(NotFound());
            }
            var leaveTypeVM = _mapper.Map <LeaveTypeViewModel>(await _repo.FindById(id));

            return(View(leaveTypeVM));
        }
Beispiel #4
0
        // GET: LeaveTypesController/Details/5
        public ActionResult Details(int id)
        {
            if (!_repo.isExists(id))
            {
                return(NotFound());
            }
            var leaveType = _repo.FindById(id);
            var model     = _mapper.Map <DetailsLeaveTypeVM>(leaveType);        //Maps the ViewModel to the database class

            return(View(model));
        }
        public ActionResult Details(int id)
        {
            if (!_leaveTypeRepo.ItExists(id))
            {
                return(Redirect("/Home/Error"));
            }

            var model = _mapper.Map <LeaveTypeVM>(_leaveTypeRepo.FindById(id));

            return(View(model));
        }
Beispiel #6
0
        // GET: LeaveTypesController/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));
        }
Beispiel #7
0
        // GET: LeaveTypes/Details/5
        public ActionResult Details(int id)
        {
            if (!_repo.isExists(id)) // provjera postoji li id u bazi
            {
                return(NotFound());  //vraca grešku 404
            }
            var leavetype = _repo.FindById(id);
            var model     = _mapper.Map <LeaveTypeVM> (leavetype);

            return(View(model));
        }
        // GET: LeaveTypesController/Details/5
        public ActionResult Details(int id)
        {
            if (!repo.Exists(id))
            {
                return(NotFound());
            }

            LeaveType   leaveType = repo.FindById(id);
            LeaveTypeVM model     = mapper.Map <LeaveTypeVM>(leaveType);

            return(View(model));
        }
Beispiel #9
0
        // GET: LeaveTypesController/Details/5
        public ActionResult Details(int id)
        {
            if (!_repo.isExisting(id))
            {
                //return RedirectToAction(nameof(Index));
                return(NotFound());
            }
            var leaveType = _repo.FindById(id);
            var model     = _mapper.Map <LeaveTypeVM>(leaveType);

            return(View(model));
        }
        // GET: LeaveTypes/Details/5
        public async Task <ActionResult> Details(int id)
        {
            if (!await _repo.isExists(id))
            {
                return(NotFound());
            }
            var leavetype = await _repo.FindById(id);

            var model = _mapper.Map <LeaveType, LeaveTypeVM>(leavetype);

            return(View(model));
        }
        // GET: LeaveTypesController/Details/5
        public ActionResult Details(int id)
        {
            var value = _repo.FindById(id.ToString());

            if (value == null)
            {
                return(NotFound());
            }

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

            return(View(model));
        }
        // GET: LeaveTypesController/Details/5
        public ActionResult Details(int id)
        {
            var leaveType = _leaveTypeRepo.FindById(id);

            if (leaveType == null)
            {
                return(NotFound());
            }

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

            return(View(model));
        }
Beispiel #13
0
        // GET: LeaveTypeController/Details/5
        public ActionResult Details(int id)
        {
            var leaveTypes = _repo.FindById(id);

            if (leaveTypes != null)
            {
                var model = _mapper.Map <LeaveType, LeaveTypeViewModel>(leaveTypes);
                return(View(model));
            }
            else
            {
                return(NotFound());
            }
        }
        // GET: LeaveTypes/Details/5
        public async Task <ActionResult> Details(int id)
        {
            var isExists = await _repo.isExist(id);

            if (!isExists)
            {
                return(NotFound());
            }
            var leavetype = await _repo.FindById(id);

            var collection = _Mapper.Map <LeaveTypeVM>(leavetype);

            return(View(collection));
        }
Beispiel #15
0
        // GET: LeaveTypesController/Details/5
        public async Task <ActionResult> Details(int id)
        {
            var isExists = await _repo.Exists(id);

            if (!isExists)
            {
                return(NotFound());
            }
            var obj = await _repo.FindById(id);

            var objVm = _mapper.Map <LeaveTypeVM>(obj);

            return(View(objVm));
        }
Beispiel #16
0
        // GET: LeaveTypes/Details/5
        public async Task <ActionResult> Details(int id)
        {
            var exists = await _repo.Exists(id); // is awaiting here any different than if (!_repo.Exists(id).Result) ?

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

            var leaveType = await _repo.FindById(id);

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

            return(View(model));
        }
        /// <summary>
        /// GET: Allocating all the leave types for all the employees for the specific period
        /// </summary>
        /// <param name="id">The id of the leave type</param>
        /// <returns></returns>
        public ActionResult SetLeave(int id)
        {
            var leaveType = _leaveTypeRepo.FindById(id);
            var employees = _userManager.GetUsersInRoleAsync("Employee").Result;

            foreach (var employee in employees)
            {
                //If the leave type was already allocated to the employee continue with the next iteration
                if (_leaveAllocationRepo.CheckAllocation(id, employee.Id))
                {
                    continue;
                }

                //If the leave type was not allocated to the employee create the allocation view model
                var allocation = new LeaveAllocationViewModel
                {
                    DateCreated  = DateTime.Now,
                    EmployeeId   = employee.Id,
                    LeaveTypeId  = id,
                    NumberOfDays = leaveType.DefaultDays,
                    Period       = DateTime.Now.Year
                };

                //Map the allocation view model to the allocation repository data
                var leaveAllocation = _mapper.Map <LeaveAllocation>(allocation);

                //Create the leave allocations entry in the database
                _leaveAllocationRepo.Create(leaveAllocation);
            }

            return(RedirectToAction(nameof(Index)));
        }
        public IActionResult AllocateLeave(int id)
        {
            var leaveType    = _leaveTypeRepo.FindById(id);
            var employeeList = _userManager.GetUsersInRoleAsync("Employee").Result;

            foreach (var emp in employeeList)
            {
                //Check if employee is not already assigned with the leaves.
                //Number of Days should be default of each leave type
                //Period for which leave has been allocated should be defined.
                if (_leaveAllocationRepo.CheckEmployeeHasLeaveAssigned(id, emp.Id) == true)
                {
                    continue;
                }
                var allocation = new LeaveAllocationVM
                {
                    LeaveTypeId  = id,
                    EmployeeId   = emp.Id,
                    NumberOfDays = 10,
                    DateCreated  = DateTime.Now
                };
                var leaveAllocationEntity = _mapper.Map <LeaveAllocation>(allocation);
                _leaveAllocationRepo.Create(leaveAllocationEntity);
            }
            return(RedirectToAction(nameof(Index)));
        }
Beispiel #19
0
        public ActionResult SetLeave(int id)
        {
            var leavetype = _leaverepo.FindById(id);
            var employees = _userManager.GetUsersInRoleAsync("Employee").Result;

            foreach (var emp in employees) //Go through the list of employee's
            {
                if (_leaveallocationrepo.CheckAllocation(id, emp.Id))
                {
                    //if their is leave allocation for this employee then continue
                    continue; //skip iteration
                }
                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);
                _leaveallocationrepo.Create(leaveallocation);
            }
            return(RedirectToAction(nameof(Index))); // Redirect back to index
        }
Beispiel #20
0
        public ActionResult SetLeave(int id)
        {
            var leaveType = _typeRepo.FindById(id);
            // get all users with Employee role
            var employees = _userManager.GetUsersInRoleAsync("Employee").Result;

            // iterate the users with employee role
            foreach (var item in employees)
            {
                // check if they already allocated to prevent duplicates
                if (_repo.CheckAllocation(id, item.Id))
                {
                    continue;
                }


                var allocation = new LeaveAllocationViewModel
                {
                    DateCreated  = DateTime.Now,
                    EmployeeId   = item.Id,
                    LeaveTypeId  = id,
                    NumberOfDays = leaveType.DefaultDays,
                    Period       = DateTime.Now.Year
                };

                // map the allocated user
                var leaveAllocated = _mapper.Map <LeaveAllocation>(allocation);

                //create mapped user for leavement
                _repo.Create(leaveAllocated);
            }

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #21
0
        public async Task <ActionResult> SetLeave(int id)
        {
            var leavetypes = await _leaverepo.FindById(id);

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

            foreach (var emp in employees)
            {
                //retriving leave type for which we are setting the employee
                if (await _leaveallocationrepo.CheckAllocation(id, emp.Id))
                {
                    continue;
                }
                var allocation = new LeaveAllocaitionVM
                {
                    DateCreated  = DateTime.Now,
                    EmployeeId   = emp.Id,
                    LeaveTypeId  = id,
                    NumberOfDays = leavetypes.DefaultDays,
                    Period       = DateTime.Now.Year
                };
                var leaveallocation = _Mapper.Map <LeaveAllocation>(allocation);
                await _leaveallocationrepo.Create(leaveallocation);
            }
            return(RedirectToAction(nameof(Index)));
        }
Beispiel #22
0
        // GET: LeaveTypesController/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);

            /* we're mapping LeaveType (data class) into LeaveTypeVM */
            var model = _mapper.Map <LeaveTypeVM>(leavetype);

            return(View(model));
        }
        public ActionResult SetLeave(int id)
        {
            var leaveType = _leaverepo.FindById(id);
            var employees = _userManager.GetUsersInRoleAsync("Employee").Result;
            var noUpdated = 0;

            foreach (var emp in employees)
            {
                if (_leaveallocationrepo.CheckAllocation(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);
                noUpdated++;
            }
            System.Diagnostics.Debug.WriteLine("No Updated: " + noUpdated);
            return(RedirectToAction(nameof(Index), new { id = noUpdated }));
        }
Beispiel #24
0
        public async Task <ActionResult> SetLeave(int id)
        {
            var leavetype = await _leaverepo.FindById(id);

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

            foreach (var emp in employees)
            {
                /* in case that leaveallcoation for this type of leave for this employee already exists */
                if (await _leaveallocationrepo.CheckAllocation(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);

                await _leaveallocationrepo.Create(leaveallocation);
            }

            return(RedirectToAction(nameof(Index)));
        }
        public ActionResult SetLeave(int id)
        {
            var leavetype = _leaverepo.FindById(id);
            var employees = _userManager.GetUsersInRoleAsync("Employee").Result;

            foreach (var emp in employees)
            {
                if (_leaveallocationrepo.CheckAllocation(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)));
        }
Beispiel #26
0
        public async Task <ActionResult> SetLeave(int id)
        {
            var leaveType = await _leaveTypeRepo.FindById(id);

            //get all users that are employees (in employee role)
            var employees = await _userManager.GetUsersInRoleAsync("Employee");

            //for each employee, create an allocation
            foreach (var employee in employees)
            {
                var check = await _LeaveAllocationrepo.CheckAllocation(leaveType.id, employee.Id);

                //skip leave allocation if the employee already has the leave
                if (check)
                {
                    continue;
                }

                var allocation = new LeaveAllocationVM
                {
                    DateCreated  = DateTime.Now,
                    EmployeeId   = employee.Id,
                    LeaveTypeId  = id,
                    NumberOfDays = leaveType.DefaultDays,
                    Period       = DateTime.Now.Year
                };

                var leaveAllocation = _mapper.Map <LeaveAllocation>(allocation);
                await _LeaveAllocationrepo.Create(leaveAllocation);
            }

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <ActionResult> SetLeave(int Id)
        {
            var leaveType = await _leaverepo.FindById(Id);

            var employees = await _userManager.GetUsersInRoleAsync("employee");

            foreach (var emp in employees)
            {
                var myAllocation = await _leaveallocationrepo.CheckAllocation(Id, emp.Id);

                if (myAllocation)
                {
                    continue;
                }
                var allocation = new LeaveAllocation
                {
                    DateCreated  = DateTime.Now,
                    EmployeeId   = emp.Id,
                    LeaveTypeId  = Id,
                    NumberOfDays = leaveType.DefaultDays,
                    Period       = DateTime.Now.Year
                };
                var leaveallocation = _mapper.Map <LeaveAllocation>(allocation);
                await _leaveallocationrepo.Create(leaveallocation);
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <ActionResult> SetLeave(int id)//find which leave type is clicked
        {
            var leavetype = await _leaverepo.FindById(id);

            //set the number that assosiated with this type in the employee
            var employees = await _userManager.GetUsersInRoleAsync("Employee");

            //now i have the type and the employee
            //retrive leave type and the employee and add ech recored to the employees
            foreach (var emp in employees)
            {
                if (await _leaveallocationrepo.CheckAllocation(id, emp.Id))
                {
                    continue;  //if yes enter the iteration
                }
                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);
                await _leaveallocationrepo.create(leaveallocation);
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <ActionResult> SetLeave(int id)
        {
            var leaveType = await _leaveRepo.FindById(id);

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

            int counter = 0;

            foreach (var e in employees)
            {
                bool isAllocationAvailable = await _leaveAllocationRepo.CheckAllocation(id, e.Id);

                if (isAllocationAvailable)
                {
                    continue;
                }
                var allocation = new LeaveAllocationVM
                {
                    DateCreated  = DateTime.Now,
                    EmployeeId   = e.Id,
                    LeaveTypeId  = id,
                    NumberOfDays = leaveType.DefaultDays,
                    Period       = DateTime.Now.Year
                };
                var leaveAllocation = _mapper.Map <LeaveAllocation>(allocation);
                await _leaveAllocationRepo.Create(leaveAllocation);

                counter++;
            }

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> SetLeave(int leaveTypeId)
        {
            var leaveType = await leaveTypeRepository.FindById(leaveTypeId);

            var employees     = userManager.GetUsersInRoleAsync("employee").Result;
            var numberUpdated = default(int);

            foreach (var employee in employees)
            {
                if (!await leaveAllocationRepository.CheackIfAllocationExistsForEmployee(leaveTypeId, employee.Id))
                {
                    var allocation = new LeaveAllocationVM
                    {
                        DateCreated  = DateTime.Now,
                        EmployeeId   = employee.Id,
                        LeaveTypeId  = leaveTypeId,
                        NumberOfDays = leaveType.DeafaultNumberOfDays,
                        Period       = DateTime.Now.Year
                    };

                    var leaveAllocation = mapper.Map <LeaveAllocation>(allocation);
                    await leaveAllocationRepository.Create(leaveAllocation);

                    numberUpdated++;
                }
            }

            return(RedirectToAction(nameof(Index), new { numberUpdated = numberUpdated }));
        }