Beispiel #1
0
        public bool TryCreateJobType(JobType jobType, out List <ValidationResult> validationResults)
        {
            if (jobType == null)
            {
                throw new ArgumentNullException(nameof(jobType));
            }

            validationResults = new List <ValidationResult>();

            var existing = jobTypes[jobType.Name];

            var valid = Validator.TryValidateObject(jobType, new ValidationContext(jobType), validationResults, true);

            if (existing != null)
            {
                validationResults.Add(new ValidationResult("This job type with this name already exists", new string[] { "Name" }));
                valid = false;
            }

            if (valid)
            {
                jobType.Id = Guid.NewGuid();
                jobTypes.Add(jobType);
            }

            return(valid);
        }
Beispiel #2
0
        public async Task <bool> Add(JobType item)
        {
            _repo.Add(item);
            await _unitOfWork.Save();

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Add /Update JobType
        /// </summary>
        public JobType SaveJobType(JobType jobType)
        {
            JobType dbVersion = jobTypeRepository.Find(jobType.JobTypeId);

            //Code Duplication Check
            if (jobTypeRepository.DoesJobTypeCodeExists(jobType))
            {
                throw new CaresException(Resources.EmployeeManagement.JobType.JobTypeCodeDuplicationError);
            }

            if (dbVersion != null)
            {
                UpdateJobTypePropertie(jobType, dbVersion);
                jobTypeRepository.Update(dbVersion);
            }
            else
            {
                dbVersion = new JobType();
                SetJobTypeProperties(jobType, dbVersion);
                jobTypeRepository.Add(dbVersion);
            }
            jobTypeRepository.SaveChanges();
            // To Load the proprties
            return(jobTypeRepository.Find(dbVersion.JobTypeId));
        }
Beispiel #4
0
 public JobType Add(JobType JobType)
 {
     // add new activity type
     _JobTypeRepo.Add(JobType);
     return(JobType);
 }