Beispiel #1
0
        public void SaveLeave(LeaveInfo leaveInfo)
        {
            Data.Leave leave = ConvertToDb(leaveInfo);

            _context.Leaves.Add(leave);
            _context.SaveChanges();
        }
Beispiel #2
0
 public LeaveInfo ConvertToFacade(Data.Leave leave)
 {
     return(new LeaveInfo
     {
         Id = leave.Id,
         Allowed = leave.Allowed,
         Availed = leave.Availed,
         LeaveType = leave.LeaveType,
         EmployeeInfoId = leave.EmployeeInfoId
     });
 }
Beispiel #3
0
        public void UpdateLeave(LeaveInfo leaveInfo)
        {
            Data.Leave leave = _context.Leaves.Find(leaveInfo.Id);

            if (leave != null)
            {
                ConvertToDb(leaveInfo);
                _context.SaveChanges();
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
Beispiel #4
0
        public void AvailLeaves(LeaveInfo leaveInfo)
        {
            Data.Leave casualLeaves = (from l in _context.Leaves.ToList() where l.EmployeeInfoId == leaveInfo.EmployeeInfoId && l.LeaveType == "Casual" select l).FirstOrDefault();
            Data.Leave annualLeaves = (from l in _context.Leaves.ToList() where l.EmployeeInfoId == leaveInfo.EmployeeInfoId && l.LeaveType == "Annual" select l).FirstOrDefault();

            int remainingCasualLeaves = casualLeaves.Allowed - casualLeaves.Availed;

            if (remainingCasualLeaves == 0)
            {
                int availedAnnualLeaves = annualLeaves.Availed + leaveInfo.Availed;

                annualLeaves.Availed = availedAnnualLeaves;
                _context.SaveChanges();
            }

            else
            {
                if (remainingCasualLeaves > leaveInfo.Availed || remainingCasualLeaves == leaveInfo.Availed)
                {
                    int availedCasualLeaves = casualLeaves.Availed + leaveInfo.Availed;

                    casualLeaves.Availed = availedCasualLeaves;
                    _context.SaveChanges();
                }

                else if (remainingCasualLeaves < leaveInfo.Availed)
                {
                    int availedCasualLeaves = casualLeaves.Availed + remainingCasualLeaves;

                    casualLeaves.Availed = availedCasualLeaves;
                    _context.SaveChanges();

                    annualLeaves.Availed = annualLeaves.Availed + (leaveInfo.Availed - remainingCasualLeaves);
                    _context.SaveChanges();
                }
            }
        }