Ejemplo n.º 1
0
        public JobType Update(JobType updatedJobType)
        {
            // update activity type
            var JobType = _JobTypeRepo.Update(updatedJobType);

            return(JobType);
        }
Ejemplo n.º 2
0
        public bool TryUpdateJobType(JobType jobType, out List <ValidationResult> validationResults)
        {
            if (jobType == null)
            {
                throw new ArgumentNullException(nameof(jobType));
            }

            if (jobType.Id == Guid.Empty)
            {
                throw new ArgumentException("Update requires Job Type Id", nameof(jobType));
            }

            validationResults = new List <ValidationResult>();

            var existing = jobTypes[jobType.Name];

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

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

            if (valid)
            {
                jobTypes.Update(jobType);
            }

            return(valid);
        }
Ejemplo n.º 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));
        }
        public async Task <ActionResult <JobTypeDto> > Update(int id, JobTypeRequest model)
        {
            var jobType = await _repository.GetById(id);

            if (jobType == null)
            {
                return(NotFound(JobTypeNotFound));
            }

            var result = await _repository.Update(id, model);

            return(result != null
                ? Accepted(nameof(Update), result)
                : StatusCode(StatusCodes.Status500InternalServerError, null));
        }
Ejemplo n.º 5
0
        public async Task <bool> Edit(JobType item)
        {
            var category = await _repo.GetById(item.JobTypeId);

            category.Name = item.Name;

            try
            {
                _repo.Update(category);
                await _unitOfWork.Save();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(false);
            }

            return(true);
        }