From fca12ecda60e458ab3bb42a7f19527ecd9d4ae58 Mon Sep 17 00:00:00 2001
From: Kyle Spearrin <kyle.spearrin@gmail.com>
Date: Thu, 18 May 2017 08:58:08 -0400
Subject: [PATCH] enough seats available

---
 .../Implementations/OrganizationService.cs    | 36 +++++++++----------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/Core/Services/Implementations/OrganizationService.cs b/src/Core/Services/Implementations/OrganizationService.cs
index 59c5b2f04c..932bb24eaa 100644
--- a/src/Core/Services/Implementations/OrganizationService.cs
+++ b/src/Core/Services/Implementations/OrganizationService.cs
@@ -947,33 +947,33 @@ namespace Bit.Core.Services
                 var usersToAdd = newUsersSet.Except(existingUsersSet).ToList();
 
                 var seatsAvailable = int.MaxValue;
+                var enoughSeatsAvailable = true;
                 if(organization.Seats.HasValue)
                 {
                     var userCount = await _organizationUserRepository.GetCountByOrganizationIdAsync(organizationId);
                     seatsAvailable = organization.Seats.Value - userCount;
-                    if(seatsAvailable < usersToAdd.Count)
-                    {
-                        // throw exception?
-                        return;
-                    }
+                    enoughSeatsAvailable = seatsAvailable >= usersToAdd.Count;
                 }
 
-                foreach(var user in newUsers)
+                if(enoughSeatsAvailable)
                 {
-                    if(!usersToAdd.Contains(user.ExternalId) || string.IsNullOrWhiteSpace(user.Email))
+                    foreach(var user in newUsers)
                     {
-                        continue;
-                    }
+                        if(!usersToAdd.Contains(user.ExternalId) || string.IsNullOrWhiteSpace(user.Email))
+                        {
+                            continue;
+                        }
 
-                    try
-                    {
-                        var newUser = await InviteUserAsync(organizationId, importingUserId, user.Email,
-                            OrganizationUserType.User, false, user.ExternalId, new List<SelectionReadOnly>());
-                        existingUsersIdDict.Add(newUser.ExternalId, newUser.Id);
-                    }
-                    catch(BadRequestException)
-                    {
-                        continue;
+                        try
+                        {
+                            var newUser = await InviteUserAsync(organizationId, importingUserId, user.Email,
+                                OrganizationUserType.User, false, user.ExternalId, new List<SelectionReadOnly>());
+                            existingUsersIdDict.Add(newUser.ExternalId, newUser.Id);
+                        }
+                        catch(BadRequestException)
+                        {
+                            continue;
+                        }
                     }
                 }