public async Task <IActionResult> GetDepartment([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var department = await _context.GetById(id); if (department == null) { return(NotFound()); } return(Ok(department)); }
public void Create( Employee employee, int departmentId, int positionId) { if (employee == null) { throw new ArgumentNullException(nameof(employee)); } var foundDepartment = _departmentRepo.GetById(departmentId); if (foundDepartment == null) { throw new ArgumentNullException(nameof(foundDepartment)); } employee.Department = foundDepartment; var foundPosition = _positionRepo.GetById(positionId); if (foundPosition == null) { throw new ArgumentNullException(nameof(foundPosition)); } employee.Position = foundPosition; _repository.Add(employee); }
public void Update( int id, DepartmentRequest department) { if (department == null) { throw new ArgumentNullException(nameof(department)); } var foundDepartment = _repository.GetById(id); if (foundDepartment == null) { throw new ArgumentNullException(nameof(foundDepartment)); } foundDepartment.ShortName = department.ShortName; foundDepartment.LongName = department.LongName; _repository.Update(foundDepartment); }
public void Create( Mark mark, int subnodeId, int departmentId, int mainBuilderId, int?chiefSpecialistId, int?groupLeaderId) { if (mark == null) { throw new ArgumentNullException(nameof(mark)); } var subnode = _subnodeRepo.GetById(subnodeId); if (subnode == null) { throw new ArgumentNullException(nameof(subnode)); } var uniqueConstraintViolationCheck = _repository.GetByUniqueKey( subnode.Id, mark.Code); if (uniqueConstraintViolationCheck != null) { throw new ConflictException(nameof(uniqueConstraintViolationCheck)); } mark.Subnode = subnode; var department = _departmentRepo.GetById(departmentId); if (department == null) { throw new ArgumentNullException(nameof(department)); } mark.Department = department; var mainBuilder = _employeeRepo.GetById(mainBuilderId); if (mainBuilder == null) { throw new ArgumentNullException(nameof(mainBuilder)); } if (mainBuilder.Department.Id != departmentId) { throw new ConflictException(nameof(departmentId)); } mark.MainBuilder = mainBuilder; if (chiefSpecialistId != null) { var chiefSpecialist = _employeeRepo.GetById( chiefSpecialistId.GetValueOrDefault()); if (chiefSpecialist == null) { throw new ArgumentNullException(nameof(chiefSpecialist)); } if (chiefSpecialist.Department.Id != departmentId) { throw new ConflictException(nameof(departmentId)); } mark.ChiefSpecialist = chiefSpecialist; } if (groupLeaderId != null) { var groupLeader = _employeeRepo.GetById(groupLeaderId.GetValueOrDefault()); if (groupLeader == null) { throw new ArgumentNullException(nameof(groupLeader)); } if (groupLeader.Department.Id != departmentId) { throw new ConflictException(nameof(departmentId)); } mark.GroupLeader = groupLeader; } _repository.Add(mark); _specificationService.Create(mark.Id); }
public void Update( int userId, DefaultValuesUpdateRequest defaultValues) { if (defaultValues == null) { throw new ArgumentNullException(nameof(defaultValues)); } var foundDefaultValues = _repository.GetByUserId(userId); if (foundDefaultValues == null) { throw new ArgumentNullException(nameof(foundDefaultValues)); } if (defaultValues.DepartmentId != null) { int departmentId = defaultValues.DepartmentId.GetValueOrDefault(); if (departmentId == -1) { foundDefaultValues.DepartmentId = null; } else { var department = _departmentRepo.GetById(departmentId); if (department == null) { throw new ArgumentNullException(nameof(department)); } foundDefaultValues.Department = department; } } if (defaultValues.CreatorId != null) { int creatorId = defaultValues.CreatorId.GetValueOrDefault(); if (creatorId == -1) { foundDefaultValues.CreatorId = null; } else { var creator = _employeeRepo.GetById(creatorId); if (creator == null) { throw new ArgumentNullException(nameof(creator)); } foundDefaultValues.Creator = creator; } } if (defaultValues.InspectorId != null) { int inspectorId = defaultValues.InspectorId.GetValueOrDefault(); if (inspectorId == -1) { foundDefaultValues.InspectorId = null; } else { var inspector = _employeeRepo.GetById(inspectorId); if (inspector == null) { throw new ArgumentNullException(nameof(inspector)); } foundDefaultValues.Inspector = inspector; } } if (defaultValues.NormContrId != null) { int normContrId = defaultValues.NormContrId.GetValueOrDefault(); if (normContrId == -1) { foundDefaultValues.NormContrId = null; } else { var normContr = _employeeRepo.GetById(normContrId); if (normContr == null) { throw new ArgumentNullException(nameof(normContr)); } foundDefaultValues.NormContr = normContr; } } _repository.Update(foundDefaultValues); }
public void Create( Mark mark, int userId, int subnodeId, int departmentId, int?chiefSpecialistId, int?groupLeaderId, int?normContrId) { if (mark == null) { throw new ArgumentNullException(nameof(mark)); } var subnode = _subnodeRepo.GetById(subnodeId); if (subnode == null) { throw new ArgumentNullException(nameof(subnode)); } var uniqueConstraintViolationCheck = _repository.GetByUniqueKey( subnode.Id, mark.Code); if (uniqueConstraintViolationCheck != null) { throw new ConflictException(nameof(uniqueConstraintViolationCheck)); } mark.Subnode = subnode; var department = _departmentRepo.GetById(departmentId); if (department == null) { throw new ArgumentNullException(nameof(department)); } mark.Department = department; if (chiefSpecialistId != null) { var chiefSpecialist = _employeeRepo.GetById( chiefSpecialistId.GetValueOrDefault()); if (chiefSpecialist == null) { throw new ArgumentNullException(nameof(chiefSpecialist)); } if (chiefSpecialist.Department.Id != departmentId) { throw new ConflictException(nameof(departmentId)); } mark.ChiefSpecialist = chiefSpecialist; } if (groupLeaderId != null) { var groupLeader = _employeeRepo.GetById(groupLeaderId.GetValueOrDefault()); if (groupLeader == null) { throw new ArgumentNullException(nameof(groupLeader)); } if (groupLeader.Department.Id != departmentId) { throw new ConflictException(nameof(departmentId)); } mark.GroupLeader = groupLeader; } if (normContrId != null) { var normContr = _employeeRepo.GetById( normContrId.GetValueOrDefault()); if (normContr == null) { throw new ArgumentNullException(nameof(normContr)); } if (normContr.Department.Id != departmentId) { throw new ConflictException(nameof(departmentId)); } mark.NormContr = normContr; } _repository.Add(mark); _specificationService.Create(mark.Id); _estimateTaskRepo.Add(new EstimateTask { Mark = mark, TaskText = "Разработать сметную документацию к чертежам " + MarkHelper.MakeMarkName( subnode.Node.Project.BaseSeries, subnode.Node.Code, subnode.Code, mark.Code ) + "\nСостав и объемы работ:", }); _markGeneralDataPointService.AddDefaultPoints(userId, mark); }