public void Update( int id, SpecificationUpdateRequest specification) { if (specification == null) { throw new ArgumentNullException(nameof(specification)); } var foundSpecification = _repository.GetById(id); if (foundSpecification == null) { throw new ArgumentNullException(nameof(foundSpecification)); } if (specification.IsCurrent == true) { var spec = _repository.GetCurrentByMarkId(foundSpecification.Mark.Id); spec.IsCurrent = false; _repository.Update(spec); foundSpecification.IsCurrent = true; } if (specification.Note != null) { foundSpecification.Note = specification.Note; } _repository.Update(foundSpecification); var foundMark = _markRepo.GetById(foundSpecification.Mark.Id); foundMark.EditedDate = DateTime.Now; _markRepo.Update(foundMark); }
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); }
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); }