public void Create( GeneralDataPoint generalDataPoint, int userId, int sectionId) { if (generalDataPoint == null) { throw new ArgumentNullException(nameof(generalDataPoint)); } var foundSection = _generalDataSectionRepo.GetById(sectionId); if (foundSection == null) { throw new ArgumentNullException(nameof(foundSection)); } var foundUser = _userRepo.GetById(userId); if (foundUser == null) { throw new ArgumentNullException(nameof(foundUser)); } var uniqueConstraintViolationCheck = _repository.GetByUniqueKey( userId, sectionId, generalDataPoint.Text); if (uniqueConstraintViolationCheck != null) { throw new ConflictException(uniqueConstraintViolationCheck.Id.ToString()); } generalDataPoint.Section = foundSection; generalDataPoint.User = foundUser; var currentPoints = _repository.GetAllByUserAndSectionId(userId, sectionId); if (currentPoints.Count() == 0) { generalDataPoint.OrderNum = 1; } else { generalDataPoint.OrderNum = currentPoints.Max(v => v.OrderNum) + 1; } _repository.Add(generalDataPoint); }