Example #1
0
        public bool EmployeeBalanceExists(EmployeeBalance employeeBalance)
        {
            List <VacationView> vacationViews = _employeeBalanceRepo.GetAllEmployeeBalances();
            var vacation = vacationViews.Find(v => v.employeeID == employeeBalance.EmployeeID && v.vacationID == employeeBalance.VacationID);

            return(vacation != null);
        }
Example #2
0
        public async Task <IActionResult> PutEmployeeBalance(int id, EmployeeBalance employeeBalance)
        {
            if (id != employeeBalance.ID)
            {
                return(BadRequest());
            }

            //_employeeBalanceService.StateEmployeeBalance(employeeBalance, EntityState.Modified);
            try
            {
                EmployeeBalance eb = new EmployeeBalance();
                eb = _employeeBalanceService.GetEmployeeBalance(id);
                if (eb != null)
                {
                    eb.EmployeeID = employeeBalance.EmployeeID;
                    eb.VacationID = employeeBalance.VacationID;
                    eb.Balance    = employeeBalance.Balance;
                }
                /**to validate the input of put**/
                if (_employeeBalanceService.EmployeebalanceValidationEdit(eb))
                {
                    return(BadRequest());
                }

                _employeeBalanceService.SaveEmployeeBalance();
            }
            catch (Exception)
            {
                throw;
            }
            return(Ok(employeeBalance));
        }
        public EmployeeBalance DeleteEmployeeBalance(int id)
        {
            EmployeeBalance employeeBalance = GetEmployeeBalance(id);

            context.Remove(employeeBalance);
            //context.SaveChanges();
            return(employeeBalance);
        }
Example #4
0
        public async Task <ActionResult <EmployeeBalance> > PostEmployeeBalance(EmployeeBalance employeeBalance)
        {
            /**to validate employeebalance**/
            if (_employeeBalanceService.EmployeebalanceValidationPost(employeeBalance))
            {
                return(BadRequest());
            }

            _employeeBalanceService.AddEmployeeBalance(employeeBalance);
            _employeeBalanceService.SaveEmployeeBalance();

            return(CreatedAtAction("GetEmployeeBalance", new { id = employeeBalance.ID }, employeeBalance));
        }
 public void UpdateEmployeeBalances(VacationView[] vacationViewArrays)
 {
     foreach (VacationView vacationView in vacationViewArrays)
     {
         EmployeeBalance eb = new EmployeeBalance();
         eb = context.EmployeeBalances.SingleOrDefault(e => e.ID == vacationView.ID);
         if (eb != null)
         {
             //eb.EmployeeID = vacationView.employeeID;
             //eb.VacationID = vacationView.vacationID;
             eb.Balance = vacationView.Balance;
         }
         //context.Update(vacationView);
     }
 }
Example #6
0
        public void AddEmployee(Employee employee)
        {
            employeeRepository.AddEmployee(employee);

            List <Vacation> vacations = vacationRepository.GetAllVacations(); //get vacation list of all our vacation

            foreach (Vacation vacation in vacations)                          //loop in each one of them and add employee to each vacation with its default value
            {
                EmployeeBalance employeeBalance = new EmployeeBalance();
                employeeBalance.Employee = employee;
                employeeBalance.Vacation = vacation;
                employeeBalance.Balance  = vacation.Balance;
                employeeBalanceRepository.AddEmployeeBalance(employeeBalance);
            }
        }
        public void AddVacation(Vacation vacation)
        {
            _vacationRepo.AddVacation(vacation);

            List <Employee> employees = _employeeRepo.GetAllEmployees();

            foreach (Employee employee in employees)
            {
                EmployeeBalance employeeBalance = new EmployeeBalance
                {
                    Employee = employee,
                    Vacation = vacation,
                    Balance  = vacation.Balance
                };
                _employeeBalanceRepo.AddEmployeeBalance(employeeBalance);
            }
        }
 public void StateEmployeeBalance(EmployeeBalance employeeBalance, EntityState state)
 {
     context.Entry(employeeBalance).State = state;
 }
 public void UpdateEmployeeBalance(EmployeeBalance employeeBalance)
 {
     context.Update(employeeBalance);
     //context.SaveChanges();
 }
 public void AddEmployeeBalance(EmployeeBalance employeeBalance)
 {
     context.Add(employeeBalance);
     //_context.SaveChanges();
 }
Example #11
0
 private bool checkVacaionBalance(EmployeeBalance employeeBalance)
 {
     return(employeeBalance.Balance > _vacationRepo.GetVacation(employeeBalance.VacationID).Balance);
 }
Example #12
0
 public bool EmployeebalanceValidationEdit(EmployeeBalance employeeBalance)
 {
     return(positiveValidator(employeeBalance.Balance) || checkVacaionBalance(employeeBalance));
 }
Example #13
0
 public void StateEmployeeBalance(EmployeeBalance employeeBalance, EntityState state)
 {
     _employeeBalanceRepo.StateEmployeeBalance(employeeBalance, state);
 }
Example #14
0
 public void UpdateEmployeeBalance(EmployeeBalance employeeBalance)
 {
     _employeeBalanceRepo.UpdateEmployeeBalance(employeeBalance);
 }
Example #15
0
 public void AddEmployeeBalance(EmployeeBalance employeeBalance)
 {
     _employeeBalanceRepo.AddEmployeeBalance(employeeBalance);
 }