public void PairClientTherapist_WithCode(string clientId, string code) { var client = _fysioDbContext.ApplicationUser.Find(clientId); if (client == null) { throw new ArgumentException(nameof(clientId)); } var therapistLink = _fysioDbContext.PairingCodes.FirstOrDefault(pc => pc.Code == code); if (therapistLink == null) { throw new ArgumentException(nameof(code)); } client.ClientTherapists = new List <TherapistClient>() { new TherapistClient() { TherapistId = therapistLink.TherapistId } }; _fysioDbContext.SaveChanges(); }
public void New(string therapistId) { List <string> existingCodes = _fysioDbContext.PairingCodes.Select(pc => pc.Code).ToList(); while (true) { string code = _random.Next(10000).ToString().PadLeft(5, '0'); if (!existingCodes.Contains(code)) { _fysioDbContext.PairingCodes.Add( new PairingCodes { TherapistId = therapistId, Code = code }); break; } } _fysioDbContext.SaveChanges(); }