Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }