示例#1
0
 public WebEmployeeHours(EmployeeHours e)
 {
     this.Value      = e.Value;
     this.TimePeriod = e.TimePeriod.ToString();
     this.Id         = e.EmployeeHoursId;
     this.EmployeeId = e.EmployeeId;
 }
示例#2
0
 public EmployeeHours(EmployeeHours employeeHours, int v)
 {
     this.Value           = employeeHours.Value;
     this.TimePeriod      = employeeHours.TimePeriod;
     this.EmployeeId      = employeeHours.EmployeeId;
     this.EmployeeHoursId = v;
 }
        public void DeleteEmployeeHours(int employeeHoursId)
        {
            EmployeeHours eh = GetOneEmployeeHours(employeeHoursId);

            if (eh == null)
            {
                return;
            }
            dbContext.EmployeeHoursCollection.Remove(eh);
            dbContext.SaveChanges();
            _log.Info(String.Format("EmployeeHours deleted from db: {0}", eh));
        }
        public void AddEmployeeHours(EmployeeHours employeeHours, bool keepId = false)
        {
            VerifyEmployeeHours(employeeHours);
            EmployeeHours employeeHoursWithId;

            // the IDs for employeeHours are common for all employes, thus use this.GetAllEmployeeHours()
            // instead of this.GetAllEmployeeHours(employeeHours.employeeId)
            var existingObjects = this.GetAllEmployeeHours();

            if (keepId)
            {
                employeeHoursWithId = new EmployeeHours(employeeHours, employeeHours.EmployeeHoursId);
            }
            else
            {
                int maxId = 0;
                for (int i = 0; i < existingObjects.Count(); i++)
                {
                    if (existingObjects[i].EmployeeHoursId > maxId)
                    {
                        maxId = existingObjects[i].EmployeeHoursId;
                    }
                }
                employeeHoursWithId = new EmployeeHours(employeeHours, maxId + 1);
            }

            var objWithIdExistng = existingObjects.Where(
                e => e.EmployeeHoursId == employeeHoursWithId.EmployeeHoursId).FirstOrDefault();

            if (objWithIdExistng != null)
            {
                throw new ArgumentException(String.Format("EmployeeHours with EmployeeHoursId: {0} already exists", employeeHoursWithId.EmployeeHoursId));
            }

            var objWithTimePeriodAndEmployeeIdExistng = existingObjects.Where(
                e => (e.TimePeriod == employeeHoursWithId.TimePeriod && e.EmployeeId == employeeHoursWithId.EmployeeId)).FirstOrDefault();

            if (objWithTimePeriodAndEmployeeIdExistng != null)
            {
                throw new ArgumentException(String.Format("EmployeeHours with EmployeeId: {0} and TimePeriod {1} already exists",
                                                          objWithTimePeriodAndEmployeeIdExistng.EmployeeId, objWithTimePeriodAndEmployeeIdExistng.TimePeriod));
            }

            _log.Debug(String.Format("Adding employeeHours to db: {0}", employeeHoursWithId));
            dbContext.EmployeeHoursCollection.Add(employeeHoursWithId);
            dbContext.SaveChanges();
            _log.Info(String.Format("EmployeeHours added to db: {0}", employeeHoursWithId));
        }
        public void EditEmployeeHours(EmployeeHours employeeHours)
        {
            EmployeeHours eh = GetOneEmployeeHours(employeeHours.EmployeeHoursId);

            if (eh == null)
            {
                throw new InvalidOperationException("EmployeeHours object not found");
            }
            VerifyEmployeeHours(employeeHours);

            this.DeleteEmployeeHours(employeeHours.EmployeeHoursId);
            dbContext.SaveChanges();
            this.AddEmployeeHours(employeeHours, true);
            dbContext.SaveChanges();
            _log.Info(String.Format("EmployeeHours edited in db: {0}", employeeHours));
        }
        private void VerifyEmployeeHours(EmployeeHours employeeHours)
        {
            int employeeId = employeeHours.EmployeeId;

            if (employeeId == -1)
            {
                throw new ArgumentException("EmployeeId was not set");
            }
            if (employeeHours.Value < 0)
            {
                throw new ArgumentException("Value < 0");
            }

            var existingEmployees = this.GetAllEmployees();
            var employeeWithId    = existingEmployees.Where(e => e.EmployeeId == employeeId).FirstOrDefault();

            if (employeeWithId == null)
            {
                throw new ArgumentException(String.Format("Employee with Id: {0} not found", employeeId));
            }
        }
示例#7
0
        public void EditEmployeeHours(WebEmployeeHours employeeHours)
        {
            var eh = new EmployeeHours(employeeHours);

            daoService.EditEmployeeHours(eh);
        }
示例#8
0
        public void AddEmployeeHours(WebEmployeeHours employeeHours)
        {
            var eh = new EmployeeHours(employeeHours);

            daoService.AddEmployeeHours(eh);
        }