public virtual bool AddBonusToEmployeeList(int departmentId, Bonuses bonus, string employeeIdsList) { try { EmployeeSalaryRepository empSalRepo = new EmployeeSalaryRepository(); BonusRepository bonusRepo = new BonusRepository(); BonusesRepository bonusesRepo = new BonusesRepository(); var idList = employeeIdsList.Trim().Split(','); var salaryBonus = from empSal in empSalRepo.GetAll() join bon in bonusRepo.GetAll() on empSal.BonusId equals bon.BonusId select new { EmployeeId = empSal.EmployeeId, BonusId = empSal.BonusId }; salaryBonus = salaryBonus.Where(item => idList.Contains(item.EmployeeId.ToString())); foreach (var item in salaryBonus) { Bonuses bonusesItem = new Bonuses { BonusId = item.BonusId, BonusValue = bonus.BonusValue, BonusDescription = bonus.BonusDescription, BonusesDate = bonus.BonusesDate }; bonusesRepo.Insert(bonusesItem); Bonus tempBonus = bonusRepo.Get(item.BonusId); tempBonus.BonusValue += bonus.BonusValue; bonusRepo.Update(tempBonus, item.BonusId); } return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } }
public virtual bool AssignBonusToEmployee(Bonuses bonus, int EmployeeId) { try { EmployeeSalaryRepository empSalRepo = new EmployeeSalaryRepository(); BonusRepository bonusRepo = new BonusRepository(); BonusesRepository bonusesRepo = new BonusesRepository(); var salaryBonus = from empSal in empSalRepo.GetAll() join bon in bonusRepo.GetAll() on empSal.BonusId equals bon.BonusId select new { EmployeeId = empSal.EmployeeId, BonusId = empSal.BonusId }; salaryBonus = salaryBonus.Where(item => item.EmployeeId == EmployeeId); foreach (var item in salaryBonus) { Bonuses bonusesItem = new Bonuses { BonusId = item.BonusId, BonusValue = bonus.BonusValue, BonusDescription = bonus.BonusDescription, BonusesDate = bonus.BonusesDate }; bonusesRepo.Insert(bonusesItem); Bonus tempBonus = bonusRepo.Get(item.BonusId); tempBonus.BonusValue += bonus.BonusValue; bonusRepo.Update(tempBonus, item.BonusId); } return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } }
public virtual async Task <bool> AddDepartmentWideBonus(int departmentId, Bonuses bonus) { try { EmployeeSalaryRepository empSalRepo = new EmployeeSalaryRepository(); BonusRepository bonusRepo = new BonusRepository(); BonusesRepository bonusesRepo = new BonusesRepository(); var salaryBonus = from empSal in empSalRepo.GetAll().Result join bon in bonusRepo.GetAll().Result on empSal.BonusId equals bon.BonusId select new { BonusId = empSal.BonusId }; foreach (var item in salaryBonus) { Bonuses bonusesItem = new Bonuses(); bonusesItem.BonusId = item.BonusId; bonusesItem.BonusValue = bonus.BonusValue; bonusesItem.BonusDescription = bonus.BonusDescription; bonusesItem.BonusesDate = bonus.BonusesDate; await bonusesRepo.Insert(bonusesItem); Bonus tempBonus = bonusRepo.Get(item.BonusId).Result; tempBonus.BonusValue += bonus.BonusValue; await bonusRepo.Update(tempBonus, item.BonusId); } return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } }