Ejemplo n.º 1
0
        public async Task CreateEmployeeVacation(CreateEmployeeVacationInput input)
        {
            input.Status = VacationStatus.PendingForManager;
            var vacationtype = _vacationTypeRepository.GetAll().Where(x => x.TypeOfVacation == "Permission").FirstOrDefault();


            if (input.VacationTypeId == vacationtype.Id)
            {
                double period = EmployeeVacationRulesCheck(input, vacationtype);
                if (period > Convert.ToDouble(vacationtype.Limit))
                {
                    throw new Abp.UI.UserFriendlyException("Error!", "Sorry, you can't take more than " + Convert.ToDouble(vacationtype.Limit) + " " + vacationtype.Unit.ToString() + " as permissions.");
                }
                else
                {
                    var employeevacation = ObjectMapper.Map <EmployeeVacation>(input);
                    await _employeeVacationsRepository.InsertAsync(employeevacation);
                }
            }
            else
            {
                var employeevacation = ObjectMapper.Map <EmployeeVacation>(input);
                await _employeeVacationsRepository.InsertAsync(employeevacation);
            }
        }
Ejemplo n.º 2
0
        public double EmployeeVacationRulesCheck(CreateEmployeeVacationInput input, VacationType vacationtype)
        {
            var employeeperiod = _employeeVacationsRepository
                                 .GetAll()
                                 .ToList()
                                 .Where(x => x.EmpSAPCode == input.EmpSAPCode &&
                                        x.VacationTypeId == input.VacationTypeId &&
                                        x.VacationFrom.Month == input.VacationFrom.Month &&
                                        x.VacationFrom.Year == input.VacationFrom.Year &&
                                        (x.Status == VacationStatus.Done || x.Status == VacationStatus.ManagerApproved));

            TimeSpan ts;
            double   period = 0;

            foreach (var vac in employeeperiod)
            {
                ts = (vac.VacationTo - vac.VacationFrom);
                if (vacationtype.Unit == VacationUnit.Minute)
                {
                    period += ts.TotalMinutes;
                }
                else if (vacationtype.Unit == VacationUnit.Hour)
                {
                    period += ts.TotalHours;
                }
                else if (vacationtype.Unit == VacationUnit.Day)
                {
                    period += ts.TotalDays;
                }
            }

            ts = (input.VacationTo - input.VacationFrom);
            if (vacationtype.Unit == VacationUnit.Minute)
            {
                period += ts.TotalMinutes;
            }
            else if (vacationtype.Unit == VacationUnit.Hour)
            {
                period += ts.TotalHours;
            }
            else if (vacationtype.Unit == VacationUnit.Day)
            {
                period += ts.TotalDays;
            }

            return(period);
        }