Example #1
0
        public virtual async Task <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().Result
                                  join bon in bonusRepo.GetAll().Result 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
                    };
                    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);
            }
        }
Example #2
0
        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);
            }
        }