Ejemplo n.º 1
0
 public ActionResult <SpecificationResponse> Create(
     int markId)
 {
     try
     {
         var specification = _service.Create(markId);
         return(Created($"specifications/{specification.Id}",
                        _mapper.Map <SpecificationResponse>(specification)));
     }
     catch (ArgumentNullException)
     {
         return(NotFound());
     }
 }
        public void Create_ShouldCreateSpecification()
        {
            // Arrange
            int markId = _rnd.Next(1, _marks.Count());

            // Act
            var specification = _service.Create(markId);

            // Assert
            _repository.Verify(
                mock => mock.Add(It.IsAny <Specification>()), Times.Once);
            Assert.NotNull(specification.Mark);

            int maxNum = 0;

            foreach (var s in _specifications.Where(v => v.Mark.Id == markId))
            {
                if (s.Num > maxNum)
                {
                    maxNum = s.Num;
                }
            }
            Assert.Equal(maxNum + 1, specification.Num);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }