Example #1
0
        public TrainingSession AddTrainingSession(int siteId, int trainingId, int employeeId, DateTime start, int duration, bool delivered)
        {
            // Because we want to have access to the employee in position property on our training session, we need some way to load this from the database.
            // One way would be using lazy loading, so that when we request this property it is loaded from the database.  However, lazy loading is not enabled.
            // So, what we need to do is make use of the EF Context caching.  When we load something from the database, context stores this in a cache.  It is then
            // loaded for any entity that references this loaded data.  In this case, our training session references the EmployeeInPosition that we are loading below
            // As a result, when we save the training session to the database, context will set the EmployeeInPosition property of the training session for us, using
            // the cache
            ISpecification <EmployeeInPosition> specification = new Specification <EmployeeInPosition>(e => e.Id == employeeId);

            specification.FetchStrategy = specification.FetchStrategy.Include(e => e.Employee);
            var employeeInTrainingPosition = _repoEmployeeInTrainingPos.Find(specification);

            var trainingsession = new TrainingSession
            {
                SiteId            = siteId,
                TrainingId        = trainingId,
                EmployeeTrainerId = employeeId,
                Start             = start,
                DurationInMinutes = duration,
                Delivered         = delivered
            };

            _repoTrainingSession.Add(trainingsession);
            return(trainingsession);
        }
Example #2
0
        public SupportStaffShift Insert(DateTime start, DateTime end, string description, int empId, string color, string title, int recurrenceId, string recurrenceException, string recurrenceRule)
        {
            var entity = new SupportStaffShift
            {
                StartTime   = start,
                EndTime     = end,
                Description = description,
                EmployeeInSupportPositionId = empId,
                Color               = color,
                Title               = title,
                RecurrenceId        = recurrenceId,
                RecurrenceException = recurrenceException,
                RecurrenceRule      = recurrenceRule
            };

            var specification = new SharpRepository.Repository.Specifications.Specification <EmployeeInPosition>(e => e.Id == empId);

            specification.FetchStrategy = specification.FetchStrategy.Include(e => e.Employee);
            var employeeInSupportPosition = _repoEmpInSupportPos.Find(specification);

            _repoSupportStaffShift.Add(entity);
            return(entity);
        }