public Boolean CreateLeaveInfo(LeaveInfo info)
        {
            var remain = new RemainingHourRepository(_dbContext);

            if (info.EndDateTime == null)
            {
                if (remain.ViewHour(info.EmployeeId, info.StartDateTime.Year.ToString(), info.Type) >= info.HoursStartDate)
                {
                    _dbContext.LeaveInfos.Add(info);
                    _dbContext.SaveChanges();
                    return(true);
                }
                return(false);
            }
            else
            {
                int totalDays  = (info.EndDateTime - info.StartDateTime).Days;
                int totalHours = (totalDays - 1) * 8 + info.HoursStartDate + info.HoursEndDate;
                if (remain.ViewHour(info.EmployeeId, info.StartDateTime.Year.ToString(), info.Type) >= totalHours)
                {
                    _dbContext.LeaveInfos.Add(info);
                    _dbContext.SaveChanges();
                    return(true);
                }
                return(false);
            }
        }
Пример #2
0
        public void Insert(T entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            Entities.Add(entity);

            _context.SaveChanges();
        }
Пример #3
0
        public void CreateLeaveType()

        {
            var       appDbContext = new LeaveManagementDbContext();
            LeaveType l            = new LeaveType();

            l = appDbContext.LeaveTypes.Where(t => t.LeaveTypeName == "Loss of Pay").FirstOrDefault();
            if (l == null)
            {
                LeaveType l1 = new LeaveType();
                l1.LeaveTypeName = "Loss of Pay";
                appDbContext.LeaveTypes.Add(l1);
                appDbContext.SaveChanges();
            }
            l = appDbContext.LeaveTypes.Where(t => t.LeaveTypeName == "Compensatory").FirstOrDefault();
            if (l == null)
            {
                LeaveType l1 = new LeaveType();
                l1.LeaveTypeName = "Compensatory";
                appDbContext.LeaveTypes.Add(l1);
                appDbContext.SaveChanges();
            }
        }
 public void Add(Employee employee)
 {
     _dbContext.Employees.Add(employee);
     _dbContext.SaveChanges();
 }