Exemplo n.º 1
0
        public Specification Create(int markId)
        {
            var foundMark = _markRepo.GetById(markId);

            if (foundMark == null)
            {
                throw new ArgumentNullException(nameof(foundMark));
            }
            var specifications = _repository.GetAllByMarkId(markId);

            foreach (var s in specifications)
            {
                if (s.IsCurrent)
                {
                    s.IsCurrent = false;
                    _repository.Update(s);
                }
            }

            var newSpecification = new Specification
            {
                Mark = foundMark,
                Num  = (Int16)(specifications.Count() == 0 ? 1 :
                               specifications.Max(v => v.Num) + 1),
                IsCurrent = true,
            };

            _repository.Add(newSpecification);

            foundMark.EditedDate = DateTime.Now;
            _markRepo.Update(foundMark);

            return(newSpecification);
        }
Exemplo n.º 2
0
        public void Create(
            AttachedDoc attachedDoc,
            int markId)
        {
            if (attachedDoc == null)
            {
                throw new ArgumentNullException(nameof(attachedDoc));
            }
            var foundMark = _markRepo.GetById(markId);

            if (foundMark == null)
            {
                throw new ArgumentNullException(nameof(foundMark));
            }

            var uniqueConstraintViolationCheck = _repository.GetByUniqueKey(
                markId, attachedDoc.Designation);

            if (uniqueConstraintViolationCheck != null)
            {
                throw new ConflictException(
                          uniqueConstraintViolationCheck.Id.ToString());
            }

            attachedDoc.Mark = foundMark;
            _repository.Add(attachedDoc);

            foundMark.EditedDate = DateTime.Now;
            _markRepo.Update(foundMark);
        }
Exemplo n.º 3
0
        public void Create(
            StandardConstruction standardConstruction,
            int specificationId)
        {
            if (standardConstruction == null)
            {
                throw new ArgumentNullException(nameof(standardConstruction));
            }
            var foundSpecification = _specificationRepo.GetById(specificationId);

            if (foundSpecification == null)
            {
                throw new ArgumentNullException(nameof(foundSpecification));
            }

            var uniqueConstraintViolationCheck = _repository.GetByUniqueKey(
                specificationId, standardConstruction.Name);

            if (uniqueConstraintViolationCheck != null)
            {
                throw new ConflictException(nameof(uniqueConstraintViolationCheck));
            }

            standardConstruction.Specification = foundSpecification;

            _repository.Add(standardConstruction);

            var foundMark = _markRepo.GetById(foundSpecification.Mark.Id);

            foundMark.EditedDate = DateTime.Now;
            _markRepo.Update(foundMark);
        }
Exemplo n.º 4
0
        public void Create(
            Construction construction,
            int specificationId,
            int typeId,
            int?subtypeId,
            int weldingControlId)
        {
            if (construction == null)
            {
                throw new ArgumentNullException(nameof(construction));
            }
            var foundSpecification = _specificationRepo.GetById(specificationId);

            if (foundSpecification == null)
            {
                throw new ArgumentNullException(nameof(foundSpecification));
            }

            var uniqueConstraintViolationCheck = _repository.GetByUniqueKey(
                specificationId, construction.Name, construction.PaintworkCoeff);

            if (uniqueConstraintViolationCheck != null)
            {
                throw new ConflictException(uniqueConstraintViolationCheck.Id.ToString());
            }

            construction.Specification = foundSpecification;

            var foundType = _constructionTypeRepo.GetById(typeId);

            if (foundType == null)
            {
                throw new ArgumentNullException(nameof(foundType));
            }
            construction.Type = foundType;
            if (subtypeId != null)
            {
                var subtype = _constructionSubtypeRepo.GetById(subtypeId.GetValueOrDefault());
                if (subtype == null)
                {
                    throw new ArgumentNullException(nameof(subtype));
                }
                construction.Subtype = subtype;
            }
            var foundWeldingControl = _weldingControlRepo.GetById(weldingControlId);

            if (foundWeldingControl == null)
            {
                throw new ArgumentNullException(nameof(foundWeldingControl));
            }
            construction.WeldingControl = foundWeldingControl;

            _repository.Add(construction);

            var foundMark = _markRepo.GetById(foundSpecification.Mark.Id);

            foundMark.EditedDate = DateTime.Now;
            _markRepo.Update(foundMark);
        }
Exemplo n.º 5
0
        public void Create(
            MarkGeneralDataPoint markGeneralDataPoint,
            int markId,
            int sectionId)
        {
            if (markGeneralDataPoint == null)
            {
                throw new ArgumentNullException(nameof(markGeneralDataPoint));
            }
            var foundSection = _generalDataSectionRepo.GetById(sectionId);

            if (foundSection == null)
            {
                throw new ArgumentNullException(nameof(foundSection));
            }
            var foundMark = _markRepo.GetById(markId);

            if (foundMark == null)
            {
                throw new ArgumentNullException(nameof(foundMark));
            }

            var uniqueConstraintViolationCheck = _repository.GetByUniqueKey(
                markId, sectionId, markGeneralDataPoint.Text);

            if (uniqueConstraintViolationCheck != null)
            {
                throw new ConflictException(uniqueConstraintViolationCheck.Id.ToString());
            }

            markGeneralDataPoint.Section = foundSection;
            markGeneralDataPoint.Mark    = foundMark;

            var currentPoints = _repository.GetAllByMarkAndSectionId(markId, sectionId);

            if (currentPoints.Count() == 0)
            {
                markGeneralDataPoint.OrderNum = 1;
            }
            else
            {
                markGeneralDataPoint.OrderNum = (Int16)(currentPoints.Max(v => v.OrderNum) + 1);
            }

            _repository.Add(markGeneralDataPoint);

            foundMark.EditedDate = DateTime.Now;
            _markRepo.Update(foundMark);
        }
Exemplo n.º 6
0
        public void Update(
            int markId,
            List <int> employeeIds)
        {
            Log.Information(JsonSerializer.Serialize(employeeIds));
            if (employeeIds == null)
            {
                throw new ArgumentNullException(nameof(employeeIds));
            }
            var foundMark = _markRepo.GetById(markId);

            if (foundMark == null)
            {
                throw new ArgumentNullException(nameof(foundMark));
            }

            var employees = new List <Employee> {
            };

            foreach (var id in employeeIds)
            {
                var employee = _employeeRepo.GetById(id);
                if (employee == null)
                {
                    throw new ArgumentNullException(nameof(employee));
                }
                employees.Add(employee);
            }

            var markApprovals      = _repository.GetAllByMarkId(markId);
            var currentEmployeeIds = new List <int> {
            };

            foreach (var ma in markApprovals)
            {
                if (!employeeIds.Contains(ma.Employee.Id))
                {
                    _repository.Delete(ma);
                }
                currentEmployeeIds.Add(ma.Employee.Id);
            }

            foreach (var(id, i) in employeeIds.WithIndex())
            {
                if (!currentEmployeeIds.Contains(id))
                {
                    _repository.Add(
                        new MarkApproval
                    {
                        Mark     = foundMark,
                        Employee = employees[i],
                    });
                }
            }

            foundMark.EditedDate = DateTime.Now;
            _markRepo.Update(foundMark);
        }
Exemplo n.º 7
0
        public void Create(
            ConstructionElement constructionElement,
            int constructionId,
            int profileId,
            int steelId)
        {
            if (constructionElement == null)
            {
                throw new ArgumentNullException(nameof(constructionElement));
            }
            var foundConstruction = _constructionRepo.GetById(constructionId);

            if (foundConstruction == null)
            {
                throw new ArgumentNullException(nameof(foundConstruction));
            }
            var foundProfile = _profileRepo.GetById(profileId);

            if (foundProfile == null)
            {
                throw new ArgumentNullException(nameof(foundProfile));
            }
            var foundSteel = _steelRepo.GetById(steelId);

            if (foundSteel == null)
            {
                throw new ArgumentNullException(nameof(foundSteel));
            }

            // var uniqueConstraintViolationCheck = _repository.GetByUniqueConstraint(markId, linkedDocId);
            // if (uniqueConstraintViolationCheck != null)
            //     throw new ConflictException(nameof(uniqueConstraintViolationCheck));

            constructionElement.Construction = foundConstruction;
            constructionElement.Profile      = foundProfile;
            constructionElement.Steel        = foundSteel;

            _repository.Add(constructionElement);

            var foundMark = _markRepo.GetById(foundConstruction.Specification.Mark.Id);

            foundMark.EditedDate = DateTime.Now;
            _markRepo.Update(foundMark);
        }
Exemplo n.º 8
0
        public void Create(
            ConstructionBolt constructionBolt,
            int constructionId,
            int boltDiameterId)
        {
            if (constructionBolt == null)
            {
                throw new ArgumentNullException(nameof(constructionBolt));
            }
            var foundConstruction = _constructionRepo.GetById(constructionId);

            if (foundConstruction == null)
            {
                throw new ArgumentNullException(nameof(foundConstruction));
            }
            var foundBoltDiameter = _boltDiameterRepo.GetById(boltDiameterId);

            if (foundBoltDiameter == null)
            {
                throw new ArgumentNullException(nameof(foundBoltDiameter));
            }

            var uniqueConstraintViolationCheck = _repository.GetByUniqueKey(constructionId, boltDiameterId);

            if (uniqueConstraintViolationCheck != null)
            {
                throw new ConflictException(nameof(uniqueConstraintViolationCheck));
            }

            constructionBolt.Construction = foundConstruction;
            constructionBolt.Diameter     = foundBoltDiameter;

            _repository.Add(constructionBolt);

            var foundMark = _markRepo.GetById(foundConstruction.Specification.Mark.Id);

            foundMark.EditedDate = DateTime.Now;
            _markRepo.Update(foundMark);
        }
Exemplo n.º 9
0
        public void Create(
            AdditionalWork additionalWork,
            int markId,
            int employeeId)
        {
            if (additionalWork == null)
            {
                throw new ArgumentNullException(nameof(AdditionalWork));
            }
            var foundMark = _markRepo.GetById(markId);

            if (foundMark == null)
            {
                throw new ArgumentNullException(nameof(foundMark));
            }
            var foundEmployee = _employeeRepo.GetById(employeeId);

            if (foundEmployee == null)
            {
                throw new ArgumentNullException(nameof(foundEmployee));
            }

            var uniqueConstraintViolationCheck = _repository.GetByUniqueKey(
                markId, employeeId);

            if (uniqueConstraintViolationCheck != null)
            {
                throw new ConflictException(
                          uniqueConstraintViolationCheck.Id.ToString());
            }

            additionalWork.Mark     = foundMark;
            additionalWork.Employee = foundEmployee;
            _repository.Add(additionalWork);

            foundMark.EditedDate = DateTime.Now;
            _markRepo.Update(foundMark);
        }
Exemplo n.º 10
0
        public void Update(
            int markId,
            EstimateTaskUpdateRequest estimateTask)
        {
            if (estimateTask == null)
            {
                throw new ArgumentNullException(nameof(estimateTask));
            }
            var foundEstimateTask = _repository.GetByMarkId(markId);

            if (foundEstimateTask == null)
            {
                throw new ArgumentNullException(nameof(foundEstimateTask));
            }

            if (estimateTask.TaskText != null)
            {
                foundEstimateTask.TaskText = estimateTask.TaskText;
            }
            if (estimateTask.AdditionalText != null)
            {
                foundEstimateTask.AdditionalText = estimateTask.AdditionalText;
            }
            if (estimateTask.ApprovalEmployeeId != null)
            {
                int approvalEmployeeId = estimateTask.ApprovalEmployeeId.GetValueOrDefault();
                if (approvalEmployeeId == -1)
                {
                    foundEstimateTask.ApprovalEmployeeId = null;
                }
                else
                {
                    var approvalEmployee = _employeeRepo.GetById(approvalEmployeeId);
                    if (approvalEmployee == null)
                    {
                        throw new ArgumentNullException(nameof(approvalEmployee));
                    }
                    foundEstimateTask.ApprovalEmployee = approvalEmployee;
                }
            }
            _repository.Update(foundEstimateTask);

            var foundMark = _markRepo.GetById(markId);

            foundMark.EditedDate = DateTime.Now;
            _markRepo.Update(foundMark);
        }
Exemplo n.º 11
0
        public void Create(
            Doc doc,
            int markId,
            int docTypeId,
            int creatorId,
            int?inspectorId,
            int?normContrId)
        {
            if (doc == null)
            {
                throw new ArgumentNullException(nameof(doc));
            }
            var foundMark = _markRepo.GetById(markId);

            if (foundMark == null)
            {
                throw new ArgumentNullException(nameof(foundMark));
            }
            doc.Mark = foundMark;

            var foundDocType = _docTypeRepo.GetById(docTypeId);

            if (foundDocType == null)
            {
                throw new ArgumentNullException(nameof(foundDocType));
            }
            doc.Type = foundDocType;

            var docs   = _repository.GetAllByMarkIdAndDocType(markId, docTypeId);
            int maxNum = 0;

            foreach (var s in docs)
            {
                if (s.Num > maxNum)
                {
                    maxNum = s.Num;
                }
            }
            doc.Num = (Int16)(maxNum + 1);

            var creator = _employeeRepo.GetById(creatorId);

            if (creator == null)
            {
                throw new ArgumentNullException(nameof(creator));
            }
            doc.Creator = creator;
            if (inspectorId != null)
            {
                var inspector = _employeeRepo.GetById(inspectorId.GetValueOrDefault());
                if (inspector == null)
                {
                    throw new ArgumentNullException(nameof(inspector));
                }
                doc.Inspector = inspector;
            }
            if (normContrId != null)
            {
                var normContr = _employeeRepo.GetById(normContrId.GetValueOrDefault());
                if (normContr == null)
                {
                    throw new ArgumentNullException(nameof(normContr));
                }
                doc.NormContr = normContr;
            }
            _repository.Add(doc);

            foundMark.EditedDate = DateTime.Now;
            _markRepo.Update(foundMark);
        }
Exemplo n.º 12
0
        public void Create(MarkOperatingConditions markOperatingConditions,
                           int markId,
                           int envAggressivenessId,
                           int operatingAreaId,
                           int gasGroupId,
                           int constructionMaterialId,
                           int paintworkTypeId,
                           int highTensileBoltsTypeId)
        {
            if (markOperatingConditions == null)
            {
                throw new ArgumentNullException(nameof(markOperatingConditions));
            }
            var foundMark = _markRepo.GetById(markId);

            if (foundMark == null)
            {
                throw new ArgumentNullException(nameof(foundMark));
            }
            var uniqueConstraintViolationCheck = _repository.GetByMarkId(markId);

            if (uniqueConstraintViolationCheck != null)
            {
                throw new ConflictException(nameof(uniqueConstraintViolationCheck));
            }
            markOperatingConditions.Mark = foundMark;

            var envAggressiveness = _envAggressivenessRepo.GetById(envAggressivenessId);

            if (envAggressiveness == null)
            {
                throw new ArgumentNullException(nameof(envAggressiveness));
            }
            markOperatingConditions.EnvAggressiveness = envAggressiveness;

            var operatingArea = _operatingAreaRepo.GetById(operatingAreaId);

            if (operatingArea == null)
            {
                throw new ArgumentNullException(nameof(operatingArea));
            }
            markOperatingConditions.OperatingArea = operatingArea;

            var gasGroup = _gasGroupRepo.GetById(gasGroupId);

            if (gasGroup == null)
            {
                throw new ArgumentNullException(nameof(gasGroup));
            }
            markOperatingConditions.GasGroup = gasGroup;

            var constructionMaterial = _constructionMaterialRepo.GetById(constructionMaterialId);

            if (constructionMaterial == null)
            {
                throw new ArgumentNullException(nameof(constructionMaterial));
            }
            markOperatingConditions.ConstructionMaterial = constructionMaterial;

            var paintworkType = _paintworkTypeRepo.GetById(paintworkTypeId);

            if (paintworkType == null)
            {
                throw new ArgumentNullException(nameof(paintworkType));
            }
            markOperatingConditions.PaintworkType = paintworkType;

            var highTensileBoltsType = _highTensileBoltsTypeRepo.GetById(highTensileBoltsTypeId);

            if (highTensileBoltsType == null)
            {
                throw new ArgumentNullException(nameof(highTensileBoltsType));
            }
            markOperatingConditions.HighTensileBoltsType = highTensileBoltsType;

            _repository.Add(markOperatingConditions);

            foundMark.EditedDate = DateTime.Now;
            _markRepo.Update(foundMark);
        }
Exemplo n.º 13
0
        public void Update(
            int id,
            MarkUpdateRequest mark)
        {
            if (mark == null)
            {
                throw new ArgumentNullException(nameof(mark));
            }
            var foundMark = _repository.GetById(id);

            if (foundMark == null)
            {
                throw new ArgumentNullException(nameof(foundMark));
            }
            if (mark.Name != null)
            {
                foundMark.Name = mark.Name;
            }

            if ((mark.Code != null) && (mark.SubnodeId != null))
            {
                foundMark.Code = mark.Code;

                var subnode = _subnodeRepo.GetById(mark.SubnodeId.GetValueOrDefault());
                if (subnode == null)
                {
                    throw new ArgumentNullException(nameof(subnode));
                }
                foundMark.Subnode = subnode;

                var uniqueConstraintViolationCheck = _repository.GetByUniqueKey(
                    subnode.Id, mark.Code);
                if (uniqueConstraintViolationCheck != null && uniqueConstraintViolationCheck.Id != id)
                {
                    throw new ConflictException(nameof(uniqueConstraintViolationCheck));
                }
            }
            else if (mark.Code != null)
            {
                foundMark.Code = mark.Code;

                var uniqueConstraintViolationCheck = _repository.GetByUniqueKey(
                    foundMark.Subnode.Id, mark.Code);
                if (uniqueConstraintViolationCheck != null && uniqueConstraintViolationCheck.Id != id)
                {
                    throw new ConflictException(nameof(uniqueConstraintViolationCheck));
                }
            }
            else if (mark.SubnodeId != null)
            {
                var subnode = _subnodeRepo.GetById(mark.SubnodeId.GetValueOrDefault());
                if (subnode == null)
                {
                    throw new ArgumentNullException(nameof(subnode));
                }
                foundMark.Subnode = subnode;

                var uniqueConstraintViolationCheck = _repository.GetByUniqueKey(
                    subnode.Id, foundMark.Code);
                if (uniqueConstraintViolationCheck != null && uniqueConstraintViolationCheck.Id != id)
                {
                    throw new ConflictException(nameof(uniqueConstraintViolationCheck));
                }
            }

            if (mark.DepartmentId != null)
            {
                var department = _departmentRepo.GetById(mark.DepartmentId.GetValueOrDefault());
                if (department == null)
                {
                    throw new ArgumentNullException(nameof(department));
                }
                foundMark.Department = department;
                // To Do: Check employees
            }
            if (mark.MainBuilderId != null)
            {
                var mainBuilder = _employeeRepo.GetById(mark.MainBuilderId.GetValueOrDefault());
                if (mainBuilder == null)
                {
                    throw new ArgumentNullException(nameof(mainBuilder));
                }
                if (mainBuilder.Department.Id != foundMark.Department.Id)
                {
                    throw new ConflictException("departmentId");
                }
                foundMark.MainBuilder = mainBuilder;
            }
            // Nullable section
            if (mark.ChiefSpecialistId != null)
            {
                int chiefSpecialistId = mark.ChiefSpecialistId.GetValueOrDefault();
                if (chiefSpecialistId == -1)
                {
                    foundMark.ChiefSpecialist = null;
                }
                else
                {
                    var chiefSpecialist = _employeeRepo.GetById(chiefSpecialistId);
                    if (chiefSpecialist == null)
                    {
                        throw new ArgumentNullException(nameof(chiefSpecialist));
                    }
                    if (chiefSpecialist.Department.Id != foundMark.Department.Id)
                    {
                        throw new ConflictException("departmentId");
                    }
                    foundMark.ChiefSpecialist = chiefSpecialist;
                }
            }
            if (mark.GroupLeaderId != null)
            {
                int groupLeaderId = mark.GroupLeaderId.GetValueOrDefault();
                if (groupLeaderId == -1)
                {
                    foundMark.GroupLeader = null;
                }
                else
                {
                    var groupLeader = _employeeRepo.GetById(groupLeaderId);
                    if (groupLeader == null)
                    {
                        throw new ArgumentNullException(nameof(groupLeader));
                    }
                    if (groupLeader.Department.Id != foundMark.Department.Id)
                    {
                        throw new ConflictException("departmentId");
                    }
                    foundMark.GroupLeader = groupLeader;
                }
            }
            foundMark.EditedDate = DateTime.Now;
            _repository.Update(foundMark);
        }