/// <summary> /// Update the configurations for a service. It does not delete the configurations for the owner. /// </summary> /// <param name="updateServicePatch">Json request object representing what to update</param> /// <returns>Bool representing whether the operation passed</returns> public bool UpdateServicePrivacy(UpdateServicePatch updateServicePatch) { // Save the configuration to re add it later. var saveConfig = _context.Configuration.AsNoTracking(). Where(c => updateServicePatch.EndPoint == c.EndPoint). FirstOrDefault(); // if we couldn't find the config return false if (saveConfig == null) { return(false); } // Grab all Configuration for all the teams its open to except the owner. var configs = _context.Configuration. Where(c => updateServicePatch.EndPoint == c.EndPoint && updateServicePatch.ClientId != c.OpenTo). Select(c => new Configuration() { EndPoint = c.EndPoint, OpenTo = c.OpenTo, Steps = c.Steps }). ToList(); // Delete them all. _context.Configuration.RemoveRange(configs); // Loop through OpenTo and recreate config based on updated privacy rules. foreach (var team in updateServicePatch.OpenTo) { // Grab the client id based on username. var clientId = _context.Team.Where(t => team == t.Username).Select(t => t.ClientId).FirstOrDefault(); // If clientId is owner skip. if (clientId == updateServicePatch.ClientId) { continue; } // Skip the creation if username is not found. if (clientId == null) { continue; } else { // Recreate the configuration for the current team. _context.Configuration.Add(new Configuration() { EndPoint = saveConfig.EndPoint, OpenTo = clientId, Steps = saveConfig.Steps }); } } // Update the changes and return true. _context.SaveChanges(); return(true); }
public IActionResult UpdateServicePrivacy(UpdateServicePatch updateServicePatch) { try { return(Ok(_serviceManagementManager.UpdateServicePrivacy(updateServicePatch))); } catch { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
/// <summary> /// Update the privacy rules a service is open to /// </summary> /// <param name="updateServicePatch">Json request representing the changes</param> /// <returns>Bool representing whether the operation passed</returns> public bool UpdateServicePrivacy(UpdateServicePatch updateServicePatch) { return(_serviceManagementService.UpdateServicePrivacy(updateServicePatch)); }