/// <summary> /// Validates the user input for group parameters. /// </summary> /// <returns><c>true</c>, if input parameters for the group is valid, <c>false</c> otherwise.</returns> /// <param name="groupForEditDto">Group for creation dto.</param> /// <param name="excepts">Excepts.</param> protected bool ValidateInputForExistingGroup(GroupForEditDto groupForEditDto, ref List <Exception> excepts) { using (Validator checker = new Validator()) { //Check if the group inupt parameters are valid checker.ValidateExistingGroupName(groupForEditDto.Name, ref excepts); checker.ValidateConnectionType(groupForEditDto.VMChoice, ref excepts); checker.ValidateMin(groupForEditDto.MinVms, ref excepts); checker.ValidateMax(groupForEditDto.MaxVms, ref excepts); checker.ValidateMinMax(groupForEditDto.MinVms, groupForEditDto.MaxVms, ref excepts); checker.ValidateHotspares(groupForEditDto.NumHotspares, ref excepts); } return(excepts.Count == 0); }
public async Task <IActionResult> EditGroup(string userId, GroupForEditDto groupForEditDto) { //Method Level Variable Declarations List <Exception> excepts = new List <Exception>(); //Format the given input if (!FormatInput(groupForEditDto, ref excepts)) { var message = HandleErrors(excepts); return(BadRequest(message)); } //Validate group input parameters if (!ValidateInputForExistingGroup(groupForEditDto, ref excepts)) { var message = HandleErrors(excepts); return(BadRequest(message)); } //Validate user input parameters if (!ValidateInputForUsers(groupForEditDto, ref excepts)) { var message = HandleErrors(excepts); return(BadRequest(message)); } //Create users if they do not exist in the system and add them to the user group foreach (string dawgtag in groupForEditDto.Dawgtags) { //Verify a user exists and create them if they do not if (InitializeUser(dawgtag, ref excepts)) { AddUserToUserGroup(groupForEditDto.Name, dawgtag, ref excepts); } } //Delete the specified users from the group foreach (string dawgtag in groupForEditDto.RemoveDawgtags) { RemoveUserFromGroup(groupForEditDto.Name, dawgtag, ref excepts); } return(Ok()); }
static void Main(string[] args) { NewGroupController gc = new NewGroupController(); GroupForEditDto dto = new GroupForEditDto(); Calculator calc = new Calculator(); ScriptExecutor executor = new ScriptExecutor(); List <Exception> excepts = new List <Exception>(); IList <string> dawgtags = new List <string>(); IList <string> removeDawgtags = new List <string>(); dawgtags.Add("siu853401101"); dawgtags.Add("siu853401102"); removeDawgtags.Add("siu853401102"); dto.Name = "Computer_Science_Class"; dto.VMChoice = "Barkdoll-Guacamole-v1.4"; dto.Memory = "1GHz @ 4xCPU, 4GB of Ram"; dto.MinVms = 1; dto.MaxVms = 10; dto.NumHotspares = 1; dto.Protocol = "ssh"; dto.Dawgtags = dawgtags; dto.RemoveDawgtags = removeDawgtags; gc.CreateConnections(dto, ref excepts); //Console.Write(calc.GetNextIp()); //gc.CreateGroup("test", dto); //gc.DeleteGroup("test", "test_group_1"); //gc.EditGroup("test", dto); }