Exemple #1
0
        public async Task <ExecutionResponse <JobRoleModel> > UpdateJobRole(UpdateJobRoleModel model)
        {
            var jobRole = _jobRoleQueryRepo.GetAll().FirstOrDefault(x => x.Id == model.Id && x.Department.CompanyId == CurrentCompanyId);

            if (jobRole == null)
            {
                return new ExecutionResponse <JobRoleModel>
                       {
                           ResponseCode = ResponseCode.NotFound,
                           Message      = "No record found"
                       }
            }
            ;

            if (!_departmentQueryRepo.GetAll().Any(d => d.Id == model.DepartmentId && d.CompanyId == CurrentCompanyId))
            {
                return new ExecutionResponse <JobRoleModel>
                       {
                           ResponseCode = ResponseCode.NotFound,
                           Message      = "Department does not exist"
                       }
            }
            ;

            //update jobRole record in db
            jobRole.Name         = model.Name;
            jobRole.Description  = model.Description;
            jobRole.DepartmentId = model.DepartmentId;

            await _jobRoleCommandRepo.UpdateAsync(jobRole);

            await _jobRoleCommandRepo.SaveChangesAsync();

            return(new ExecutionResponse <JobRoleModel>
            {
                ResponseCode = ResponseCode.Ok,
                ResponseData = _mapper.Map <JobRoleModel>(jobRole)
            });
        }
Exemple #2
0
        public async Task <ExecutionResponse <JobRoleModel> > CreateJobRole(UpdateJobRoleModel model)
        {
            var oldJobRole = _jobRoleQueryRepo.GetAll().FirstOrDefault(x => x.Name.Trim().ToLower() == model.Name.Trim().ToLower() && x.Department.CompanyId == CurrentCompanyId);

            if (oldJobRole != null)
            {
                throw new Exception("Job Role already exists");
            }

            if (!_departmentQueryRepo.GetAll().Any(d => d.Id == model.DepartmentId && d.CompanyId == CurrentCompanyId))
            {
                return new ExecutionResponse <JobRoleModel>
                       {
                           ResponseCode = ResponseCode.NotFound,
                           Message      = "Department does not exist"
                       }
            }
            ;

            //save jobRole info
            var jobRole = new JobRole
            {
                Name         = model.Name,
                DepartmentId = model.DepartmentId,
                Description  = model.Description,
                CreateById   = _httpContext.GetCurrentSSOUserId()
            };

            await _jobRoleCommandRepo.InsertAsync(jobRole);

            await _jobRoleCommandRepo.SaveChangesAsync();

            return(new ExecutionResponse <JobRoleModel>
            {
                ResponseCode = ResponseCode.Ok,
                ResponseData = _mapper.Map <JobRoleModel>(jobRole)
            });
        }
Exemple #3
0
        public async Task <IActionResult> Create(UpdateJobRoleModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(GetModelStateErrors(ModelState)));
                }

                var response = await _jobRoleService.CreateJobRole(model);

                if (response.ResponseCode != ResponseCode.Ok)
                {
                    return(Ok(WebApiResponses <JobRoleModel> .ErrorOccured(response.Message)));
                }
                return(Ok(WebApiResponses <JobRoleModel> .Successful(response.ResponseData)));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(Ok(WebApiResponses <JobRoleModel> .ErrorOccured(ex.Message)));
            }
        }