Esempio n. 1
0
        public IResult Add(WorkerCreationDto workerCreationDto)
        {
            var workerMapper = _mapper.Map <Worker>(workerCreationDto);

            workerMapper.Status = true;
            _workerDal.Add(workerMapper);

            foreach (var departmentType in workerCreationDto.DepartmentTypes)
            {
                WorkerDepartmentType workerDepartmentType = new WorkerDepartmentType {
                    DepartmentTypeID = departmentType.DepartmentTypeID, WorkerID = workerMapper.WorkerID
                };
                _workerDepartmentTypeService.Add(workerDepartmentType);
            }

            Salary salary = new Salary()
            {
                WorkerID     = workerMapper.WorkerID,
                UserID       = workerCreationDto.UserID,
                SalaryAmount = 0,
            };

            _salaryService.Add(salary);

            return(new SuccessResult(Messages.WorkerAdded));
        }
Esempio n. 2
0
        public bool Add(Worker worker)
        {
            WorkerValidator validator = new WorkerValidator();
            var             result    = validator.Validate(worker);

            if (result.Errors.Count > 0)
            {
                throw new ValidationException(result.Errors);
            }
            return(_workerDal.Add(worker));
        }
Esempio n. 3
0
        public IResult AddWorker(Worker worker)
        {
            try
            {
                worker.HireDate = DateTime.Now;
                worker.QuitDate = new DateTime(1900, 01, 01, 0, 0, 0);
                _workerDal.Add(worker);

                var userRole = new UserRole
                {
                    RoleId = 2, //worker rolü
                    UserId = worker.WorkerId
                };
                var oldRole = _userRoleDal.Get(ur => ur.UserId == worker.WorkerId);
                _userRoleDal.Delete(oldRole);
                _userRoleDal.Add(userRole);
                return(new SuccessResult());
            }
            catch (Exception)
            {
                return(new ErrorResult(Messages.ErrorWhileAddingEntity));
            }
        }