private ValidationResultDTO ValidateUserGroup(CloneDeployUserGroupEntity userGroup, bool isNewUserGroup) { var validationResult = new ValidationResultDTO { Success = true }; if (isNewUserGroup) { if (_uow.UserGroupRepository.Exists(h => h.Name == userGroup.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This User Group Already Exists"; return(validationResult); } } else { var originalUserGroup = _uow.UserGroupRepository.GetById(userGroup.Id); if (originalUserGroup.Name != userGroup.Name) { if (_uow.UserGroupRepository.Exists(h => h.Name == userGroup.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This User Group Already Exists"; return(validationResult); } } } return(validationResult); }
private ValidationResultDTO ValidateClusterGroup(ClusterGroupEntity clusterGroup, bool isNewClusterGroup) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(clusterGroup.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "Cluster Group Name Is Not Valid"; return(validationResult); } if (clusterGroup.Name.ToLower() == "default") { validationResult.Success = false; validationResult.ErrorMessage = "Cluster Group Name Is Not Valid. Default Is Reserved"; return(validationResult); } if (clusterGroup.Default == 1) { var existingDefaultCluster = GetDefaultClusterGroup(); if (existingDefaultCluster != null && existingDefaultCluster.Id != clusterGroup.Id) { validationResult.Success = false; validationResult.ErrorMessage = "Only 1 Default Cluster Group Can Exist"; return(validationResult); } } if (isNewClusterGroup) { if (_uow.ClusterGroupRepository.Exists(h => h.Name == clusterGroup.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Cluster Group Already Exists"; return(validationResult); } } else { var originalClusterGroup = _uow.ClusterGroupRepository.GetById(clusterGroup.Id); if (originalClusterGroup.Name != clusterGroup.Name) { if (_uow.ClusterGroupRepository.Exists(h => h.Name == clusterGroup.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Cluster Group Already Exists"; return(validationResult); } } } return(validationResult); }
private ValidationResultDTO ValidateImageProfile(ImageProfileEntity imageProfile, bool isNewImageProfile) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(imageProfile.Name) || !imageProfile.Name.All(c => char.IsLetterOrDigit(c) || c == '_')) { validationResult.Success = false; validationResult.ErrorMessage = "Image Profile Name Is Not Valid"; return(validationResult); } if (isNewImageProfile) { if ( _uow.ImageProfileRepository.Exists( h => h.Name == imageProfile.Name && h.ImageId == imageProfile.ImageId)) { validationResult.Success = false; validationResult.ErrorMessage = "This Image Profile Already Exists"; return(validationResult); } } else { var originalImageProfile = _uow.ImageProfileRepository.GetById(imageProfile.Id); if (originalImageProfile.Name != imageProfile.Name) { if ( _uow.ImageProfileRepository.Exists( h => h.Name == imageProfile.Name && h.ImageId == imageProfile.ImageId)) { validationResult.Success = false; validationResult.ErrorMessage = "This Image Profile Already Exists"; return(validationResult); } } if (!string.IsNullOrEmpty(imageProfile.ModelMatch)) { var profilesWithModelMatch = _uow.ImageProfileRepository.Get(x => x.ModelMatch.Equals(imageProfile.ModelMatch.ToLower()) && x.Id != imageProfile.Id); if (profilesWithModelMatch.Any()) { var image = _uow.ImageRepository.GetById(profilesWithModelMatch.First().ImageId); validationResult.Success = false; validationResult.ErrorMessage = "This Model Match Already Exists On Image: " + image.Name; } } } return(validationResult); }
private ValidationResultDTO ValidateProfile(NetBootProfileEntity profile, bool isNewProfile) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(profile.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "NetBoot Profile Name Is Not Valid"; return(validationResult); } if (isNewProfile) { if (_uow.NetBootProfileRepository.Exists(h => h.Name == profile.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Profile With This Name Already Exists"; return(validationResult); } if (_uow.NetBootProfileRepository.Exists(h => h.Ip == profile.Ip)) { validationResult.Success = false; validationResult.ErrorMessage = "A Profile With This Ip Already Exists"; return(validationResult); } } else { var originalProfile = _uow.NetBootProfileRepository.GetById(profile.Id); if (originalProfile.Name != profile.Name) { if (_uow.NetBootProfileRepository.Exists(h => h.Name == profile.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Profile With This Name Already Exists"; return(validationResult); } } if (originalProfile.Ip != profile.Ip) { if (_uow.NetBootProfileRepository.Exists(h => h.Ip == profile.Ip)) { validationResult.Success = false; validationResult.ErrorMessage = "A Profile With This Ip Already Exists"; return(validationResult); } } } return(validationResult); }
private ValidationResultDTO ValidateFileFolder(FileFolderEntity fileFolder, bool isNewTemplate) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(fileFolder.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "Name Is Not Valid"; return(validationResult); } if (fileFolder.Path.Trim().EndsWith("/") || fileFolder.Path.Trim().EndsWith(@"\")) { char[] toRemove = { '/', '\\' }; var trimmed = fileFolder.Path.TrimEnd(toRemove); fileFolder.Path = trimmed; } if (fileFolder.Path.Trim().StartsWith("/") || fileFolder.Path.Trim().StartsWith(@"\")) { char[] toRemove = { '/', '\\' }; var trimmed = fileFolder.Path.TrimStart(toRemove); fileFolder.Path = trimmed; } fileFolder.Path = StringManipulationServices.WindowsToUnixFilePath(fileFolder.Path); if (isNewTemplate) { if (_uow.FileFolderRepository.Exists(h => h.Name == fileFolder.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "File / Folder Name Already Exists"; return(validationResult); } } else { var originalTemplate = _uow.FileFolderRepository.GetById(fileFolder.Id); if (originalTemplate.Name != fileFolder.Name) { if (_uow.FileFolderRepository.Exists(h => h.Name == fileFolder.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "File / Folder Already Exists"; return(validationResult); } } } return(validationResult); }
public ValidationResultDTO Update(Livro livro) { // Regra de Negocio ValidationResultDTO validation = new ValidationResultDTO(); // Reservado para criar regra negocio if (validation.Notifications.Count == 0) { validation.Id = livro.LivroId; validation.AffectedLines = _repository.Update(livro); } return(validation); }
public ValidationResultDTO Update(Instituicao instituicao) { // Regra de Negocio ValidationResultDTO validation = new ValidationResultDTO(); // Reservado para criar regra negocio if (validation.Notifications.Count == 0) { validation.Id = instituicao.InstituicaoId; validation.AffectedLines = _instituicaoRepository.Update(instituicao); } return(validation); }
private ValidationResultDTO ValidateUser(CloneDeployUserEntity user, bool isNewUser) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(user.Name) || !user.Name.All(c => char.IsLetterOrDigit(c) || c == '_')) { validationResult.Success = false; validationResult.ErrorMessage = "User Name Is Not Valid"; return(validationResult); } if (isNewUser) { if (string.IsNullOrEmpty(user.Password)) { validationResult.Success = false; validationResult.ErrorMessage = "Password Is Not Valid"; return(validationResult); } if (_uow.UserRepository.Exists(h => h.Name == user.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This User Already Exists"; return(validationResult); } } else { var originalUser = _uow.UserRepository.GetById(user.Id); if (originalUser.Name != user.Name) { if (_uow.UserRepository.Exists(h => h.Name == user.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This User Already Exists"; return(validationResult); } } } return(validationResult); }
private ValidationResultDTO ValidateAlternateServerIp(AlternateServerIpEntity alternateServerIp, bool isNewAlternateServerIp) { var validationResult = new ValidationResultDTO { Success = true }; if (!alternateServerIp.ApiUrl.Trim().EndsWith("/")) { alternateServerIp.ApiUrl += "/"; } if (string.IsNullOrEmpty(alternateServerIp.Ip) || string.IsNullOrEmpty(alternateServerIp.ApiUrl)) { validationResult.Success = false; validationResult.ErrorMessage = "Empty Values Are Not Valid"; return(validationResult); } if (isNewAlternateServerIp) { if (_uow.AlternateServerIpRepository.Exists(h => h.Ip == alternateServerIp.Ip)) { validationResult.Success = false; validationResult.ErrorMessage = "This Server Ip Already Exists"; return(validationResult); } } else { var originalAlternateServerIp = _uow.AlternateServerIpRepository.GetById(alternateServerIp.Id); if (originalAlternateServerIp.Ip != alternateServerIp.Ip) { if (_uow.AlternateServerIpRepository.Exists(h => h.Ip == alternateServerIp.Ip)) { validationResult.Success = false; validationResult.ErrorMessage = "This Server Ip Already Exists"; return(validationResult); } } } return(validationResult); }
private ValidationResultDTO ValidateEntry(BootEntryEntity bootEntry, bool isNewEntry) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(bootEntry.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "Boot Entry Name Is Not Valid"; return(validationResult); } if (isNewEntry) { using (var uow = new UnitOfWork()) { if (uow.BootEntryRepository.Exists(h => h.Name == bootEntry.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Boot Entry Already Exists"; return(validationResult); } } } else { using (var uow = new UnitOfWork()) { var originalTemplate = uow.BootEntryRepository.GetById(bootEntry.Id); if (originalTemplate.Name != bootEntry.Name) { if (uow.BootEntryRepository.Exists(h => h.Name == bootEntry.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Boot Template Already Exists"; return(validationResult); } } } } return(validationResult); }
private ValidationResultDTO ValidateImageProfile(ImageProfileEntity imageProfile, bool isNewImageProfile) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(imageProfile.Name) || !imageProfile.Name.All(c => char.IsLetterOrDigit(c) || c == '_')) { validationResult.Success = false; validationResult.ErrorMessage = "Image Profile Name Is Not Valid"; return(validationResult); } if (isNewImageProfile) { if ( _uow.ImageProfileRepository.Exists( h => h.Name == imageProfile.Name && h.ImageId == imageProfile.ImageId)) { validationResult.Success = false; validationResult.ErrorMessage = "This Image Profile Already Exists"; return(validationResult); } } else { var originalImageProfile = _uow.ImageProfileRepository.GetById(imageProfile.Id); if (originalImageProfile.Name != imageProfile.Name) { if ( _uow.ImageProfileRepository.Exists( h => h.Name == imageProfile.Name && h.ImageId == imageProfile.ImageId)) { validationResult.Success = false; validationResult.ErrorMessage = "This Image Profile Already Exists"; return(validationResult); } } } return(validationResult); }
public ValidationResultDTO Update(LocacaoLivro locacaolivro) { // Regra de Negocio ValidationResultDTO validation = new ValidationResultDTO(); // Reservado para criar regra negocio if (DateTime.Now > locacaolivro.DataDevolucao) { locacaolivro.SetarDataLiberacao(DateTime.Now.AddDays(30)); } if (validation.Notifications.Count == 0) { validation.Id = locacaolivro.LivroId; validation.AffectedLines = _locacaoLivroRepository.Update(locacaolivro); } return(validation); }
public ValidationResultDTO Add(LocacaoLivro locacaolivro) { // Regra de Negocio ValidationResultDTO validation = new ValidationResultDTO(); // Reservado para criar regra negocio if (RetornaQuantidadeLivroEmprestimo(locacaolivro.UsuarioId) > 2) { validation.Notifications.Add("Usuário excedeu a quantidade permitida de emprestimos."); } if (validation.Notifications.Count == 0) { validation.Id = _locacaoLivroRepository.Add(locacaolivro); validation.AffectedLines = 1; } return(validation); }
private ValidationResultDTO ValidateImageClassification(ImageClassificationEntity imageClassification, bool isNewImageClassification) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(imageClassification.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "Image Classification Name Is Not Valid"; return(validationResult); } if (isNewImageClassification) { if (_uow.ImageClassificationRepository.Exists(h => h.Name == imageClassification.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Image Classification Already Exists"; return(validationResult); } } else { var originalImageClassification = _uow.ImageClassificationRepository.GetById(imageClassification.Id); if (originalImageClassification.Name != imageClassification.Name) { if (_uow.ImageClassificationRepository.Exists(h => h.Name == imageClassification.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Image Classification Already Exists"; return(validationResult); } } } return(validationResult); }
private ValidationResultDTO ValidateEntry(NbiEntryEntity entry) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(entry.NbiName) || entry.NbiName.Any(c => c == ' ')) { validationResult.ErrorMessage = "Nbi Name Is Not Valid"; validationResult.Success = false; return(validationResult); } if (entry.NbiId < 1 || entry.NbiId > 65535) { validationResult.ErrorMessage = "Nbi Id Is Not Valid"; validationResult.Success = false; return(validationResult); } return(validationResult); }
private ValidationResultDTO ValidateSecondaryServer(SecondaryServerEntity secondaryServer, bool isNewSecondaryServer) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(secondaryServer.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "Secondary Server Name Is Not Valid"; return(validationResult); } if (isNewSecondaryServer) { if (_uow.SecondaryServerRepository.Exists(h => h.Name == secondaryServer.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Secondary Server Already Exists"; return(validationResult); } } else { var originalSecondaryServer = _uow.SecondaryServerRepository.GetById(secondaryServer.Id); if (originalSecondaryServer.Name != secondaryServer.Name) { if (_uow.SecondaryServerRepository.Exists(h => h.Name == secondaryServer.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Secondary Server Already Exists"; return(validationResult); } } } return(validationResult); }
private ValidationResultDTO ValidateSite(SiteEntity site, bool isNewSite) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(site.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "Site Name Is Not Valid"; return(validationResult); } if (isNewSite) { if (_uow.SiteRepository.Exists(h => h.Name == site.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Site Already Exists"; return(validationResult); } } else { var originalSite = _uow.SiteRepository.GetById(site.Id); if (originalSite.Name != site.Name) { if (_uow.SiteRepository.Exists(h => h.Name == site.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Site Already Exists"; return(validationResult); } } } return(validationResult); }
private ValidationResultDTO ValidateTemplate(BootTemplateEntity bootTemplate, bool isNewTemplate) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(bootTemplate.Name) || bootTemplate.Name.Contains(" ")) { validationResult.Success = false; validationResult.ErrorMessage = "Template Name Is Not Valid"; return(validationResult); } if (isNewTemplate) { if (_uow.BootTemplateRepository.Exists(h => h.Name == bootTemplate.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Boot Template Already Exists"; return(validationResult); } } else { var originalTemplate = _uow.BootTemplateRepository.GetById(bootTemplate.Id); if (originalTemplate.Name != bootTemplate.Name) { if (_uow.BootTemplateRepository.Exists(h => h.Name == bootTemplate.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Boot Template Already Exists"; return(validationResult); } } } return(validationResult); }
private ValidationResultDTO ValidateGroup(GroupEntity group, bool isNewGroup) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(group.Name) || !group.Name.All(c => char.IsLetterOrDigit(c) || c == '_')) { validationResult.Success = false; validationResult.ErrorMessage = "Group Name Is Not Valid"; return(validationResult); } if (isNewGroup) { if (_uow.GroupRepository.Exists(h => h.Name == group.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Group Already Exists"; return(validationResult); } } else { var originalGroup = _uow.GroupRepository.GetById(group.Id); if (originalGroup.Name != group.Name) { if (_uow.GroupRepository.Exists(h => h.Name == group.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Group Already Exists"; return(validationResult); } } } return(validationResult); }
private ValidationResultDTO ValidateSysprepTag(SysprepTagEntity sysprepTag, bool isNewSysprepTag) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(sysprepTag.Name) || !sysprepTag.Name.All(c => char.IsLetterOrDigit(c) || c == '_')) { validationResult.Success = false; validationResult.ErrorMessage = "Sysprep Tag Name Is Not Valid"; return(validationResult); } if (isNewSysprepTag) { if (_uow.SysprepTagRepository.Exists(h => h.Name == sysprepTag.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Sysprep Tag Already Exists"; return(validationResult); } } else { var originalSysprepTag = _uow.SysprepTagRepository.GetById(sysprepTag.Id); if (originalSysprepTag.Name != sysprepTag.Name) { if (_uow.SysprepTagRepository.Exists(h => h.Name == sysprepTag.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Sysprep Tag Already Exists"; return(validationResult); } } } return(validationResult); }
private ValidationResultDTO ValidateBuilding(BuildingEntity building, bool isNewBuilding) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(building.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "Building Name Is Not Valid"; return(validationResult); } if (isNewBuilding) { if (_uow.BuildingRepository.Exists(h => h.Name == building.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Building Already Exists"; return(validationResult); } } else { var originalBuilding = _uow.BuildingRepository.GetById(building.Id); if (originalBuilding.Name != building.Name) { if (_uow.BuildingRepository.Exists(h => h.Name == building.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Building Already Exists"; return(validationResult); } } } return(validationResult); }
private ValidationResultDTO ValidateManifest(MunkiManifestTemplateEntity manifest, bool isNewManifest) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(manifest.Name) || manifest.Name.Contains(" ")) { validationResult.Success = false; validationResult.ErrorMessage = "Manifest Name Is Not Valid"; return(validationResult); } if (isNewManifest) { if (_uow.MunkiManifestRepository.Exists(h => h.Name == manifest.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Manifest Already Exists"; return(validationResult); } } else { var originalManifest = _uow.MunkiManifestRepository.GetById(manifest.Id); if (originalManifest.Name != manifest.Name) { if (_uow.MunkiManifestRepository.Exists(h => h.Name == manifest.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Manifest Already Exists"; return(validationResult); } } } return(validationResult); }
private ValidationResultDTO ValidateScript(ScriptEntity script, bool isNewScript) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(script.Name) || !script.Name.All(c => char.IsLetterOrDigit(c) || c == '_')) { validationResult.Success = false; validationResult.ErrorMessage = "Script Name Is Not Valid"; return(validationResult); } if (isNewScript) { if (_uow.ScriptRepository.Exists(h => h.Name == script.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Script Already Exists"; return(validationResult); } } else { var originalScript = _uow.ScriptRepository.GetById(script.Id); if (originalScript.Name != script.Name) { if (_uow.ScriptRepository.Exists(h => h.Name == script.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Script Already Exists"; return(validationResult); } } } return(validationResult); }
private ValidationResultDTO ValidateRoom(RoomEntity room, bool isNewRoom) { var validationResult = new ValidationResultDTO { Success = true }; if (string.IsNullOrEmpty(room.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "Room Name Is Not Valid"; return(validationResult); } if (isNewRoom) { if (_uow.RoomRepository.Exists(h => h.Name == room.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Room Already Exists"; return(validationResult); } } else { var originalRoom = _uow.RoomRepository.GetById(room.Id); if (originalRoom.Name != room.Name) { if (_uow.RoomRepository.Exists(h => h.Name == room.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "This Room Already Exists"; return(validationResult); } } } return(validationResult); }
private ValidationResultDTO ValidateComputer(ComputerEntity computer, string type) { var validationResult = new ValidationResultDTO { Success = false }; if (type == "new" || type == "update") { if (string.IsNullOrEmpty(computer.Name) || computer.Name.Any(c => c == ' ')) { validationResult.ErrorMessage = "Computer Name Is Not Valid"; return(validationResult); } if (string.IsNullOrEmpty(computer.Mac) || !computer.Mac.All(c => char.IsLetterOrDigit(c) || c == ':' || c == '-') && computer.Mac.Length == 12 && !computer.Mac.All(char.IsLetterOrDigit)) { validationResult.ErrorMessage = "Computer Mac Is Not Valid"; return(validationResult); } if (type == "new") { if (_uow.ComputerRepository.Exists(h => h.Name == computer.Name)) { validationResult.ErrorMessage = "A Computer With This Name Already Exists"; return(validationResult); } if (_uow.ComputerRepository.Exists(h => h.Mac == computer.Mac)) { var existingComputer = GetComputerFromMac(computer.Mac); if (string.IsNullOrEmpty(existingComputer.ClientIdentifier) || string.IsNullOrEmpty(computer.ClientIdentifier) || existingComputer.ClientIdentifier == computer.ClientIdentifier) { validationResult.ErrorMessage = "Duplicate MAC Addresses Are Only Allowed If Each Computer Has A Unique Client Identifier"; return(validationResult); } } } else { var originalComputer = _uow.ComputerRepository.GetById(computer.Id); if (originalComputer.Name != computer.Name) { if (_uow.ComputerRepository.Exists(h => h.Name == computer.Name)) { validationResult.ErrorMessage = "A Computer With This Name Already Exists"; return(validationResult); } } else if (originalComputer.Mac != computer.Mac) { if (_uow.ComputerRepository.Exists(h => h.Mac == computer.Mac)) { var existingComputer = GetComputerFromMac(computer.Mac); if (string.IsNullOrEmpty(existingComputer.ClientIdentifier) || string.IsNullOrEmpty(computer.ClientIdentifier) || existingComputer.ClientIdentifier == computer.ClientIdentifier) { validationResult.ErrorMessage = "Duplicate MAC Addresses Are Only Allowed If Each Computer Has A Unique Client Identifier"; return(validationResult); } } } } } if (type == "delete") { if (IsComputerActive(computer.Id)) { validationResult.ErrorMessage = "A Computer Cannot Be Deleted While It Has An Active Task"; return(validationResult); } } validationResult.Success = true; return(validationResult); }
public ValidationResultDTO GlobalLogin(string userName, string password, string loginType) { var validationResult = new ValidationResultDTO { ErrorMessage = "Incorrect Username Or Password", Success = false }; var auditLog = new AuditLogEntity(); var auditLogService = new AuditLogServices(); auditLog.ObjectId = -1; auditLog.ObjectName = userName; auditLog.Ip = IpServices.GetIPAddress(); auditLog.UserId = -1; auditLog.ObjectType = "User"; auditLog.AuditType = AuditEntry.Type.FailedLogin; //Check if user exists in Clone Deploy var user = _userServices.GetUser(userName); if (user == null) { //Check For a first time LDAP User Group Login if (SettingServices.GetSettingValue(SettingStrings.LdapEnabled) == "1") { foreach (var ldapGroup in _userGroupServices.GetLdapGroups()) { if (new LdapServices().Authenticate(userName, password, ldapGroup.GroupLdapName)) { //user is a valid ldap user via ldap group that has not yet logged in. //Add the user and allow login. var cdUser = new CloneDeployUserEntity { Name = userName, Salt = Utility.CreateSalt(64), Token = Utility.GenerateKey(), IsLdapUser = 1 }; //Create a local random db pass, should never actually be possible to use. cdUser.Password = Utility.CreatePasswordHash(Utility.GenerateKey(), cdUser.Salt); if (_userServices.AddUser(cdUser).Success) { //add user to group var newUser = _userServices.GetUser(userName); _userGroupServices.AddNewGroupMember(ldapGroup.Id, newUser.Id); auditLog.UserId = newUser.Id; auditLog.ObjectId = newUser.Id; validationResult.Success = true; auditLog.AuditType = AuditEntry.Type.SuccessfulLogin; break; } } } } auditLogService.AddAuditLog(auditLog); return(validationResult); } if (_userLockoutServices.AccountIsLocked(user.Id)) { _userLockoutServices.ProcessBadLogin(user.Id); validationResult.ErrorMessage = "Account Is Locked"; auditLog.UserId = user.Id; auditLog.ObjectId = user.Id; auditLogService.AddAuditLog(auditLog); return(validationResult); } //Check against AD if (user.IsLdapUser == 1 && SettingServices.GetSettingValue(SettingStrings.LdapEnabled) == "1") { //Check if user is authenticated against an ldap group if (user.UserGroupId != -1) { //user is part of a group, is the group an ldap group? var userGroup = _userGroupServices.GetUserGroup(user.UserGroupId); if (userGroup != null) { if (userGroup.IsLdapGroup == 1) { //the group is an ldap group //make sure user is still in that ldap group if (new LdapServices().Authenticate(userName, password, userGroup.GroupLdapName)) { validationResult.Success = true; } else { //user is either not in that group anymore, not in the directory, or bad password validationResult.Success = false; if (new LdapServices().Authenticate(userName, password)) { //password was good but user is no longer in the group //delete the user _userServices.DeleteUser(user.Id); } } } else { //the group is not an ldap group //still need to check creds against directory if (new LdapServices().Authenticate(userName, password)) { validationResult.Success = true; } } } else { //group didn't exist for some reason //still need to check creds against directory if (new LdapServices().Authenticate(userName, password)) { validationResult.Success = true; } } } else { //user is not part of a group, check creds against directory if (new LdapServices().Authenticate(userName, password)) { validationResult.Success = true; } } } else if (user.IsLdapUser == 1 && SettingServices.GetSettingValue(SettingStrings.LdapEnabled) != "1") { //prevent ldap user from logging in with local pass if ldap auth gets turned off validationResult.Success = false; } //Check against local DB else { var hash = Utility.CreatePasswordHash(password, user.Salt); if (user.Password == hash) { validationResult.Success = true; } } if (validationResult.Success) { auditLog.AuditType = AuditEntry.Type.SuccessfulLogin; auditLog.UserId = user.Id; auditLog.ObjectId = user.Id; auditLogService.AddAuditLog(auditLog); _userLockoutServices.DeleteUserLockouts(user.Id); return(validationResult); } auditLog.AuditType = AuditEntry.Type.FailedLogin; auditLog.UserId = user.Id; auditLog.ObjectId = user.Id; auditLogService.AddAuditLog(auditLog); _userLockoutServices.ProcessBadLogin(user.Id); return(validationResult); }
private ValidationResultDTO ValidateDistributionPoint(DistributionPointEntity distributionPoint, bool isNewDistributionPoint) { var validationResult = new ValidationResultDTO { Success = true }; if (Convert.ToBoolean(distributionPoint.IsPrimary)) { if (!distributionPoint.PhysicalPath.Trim().EndsWith(Path.DirectorySeparatorChar.ToString())) { distributionPoint.PhysicalPath += Path.DirectorySeparatorChar; } } if (string.IsNullOrEmpty(distributionPoint.DisplayName) || distributionPoint.DisplayName.Contains(" ")) { validationResult.Success = false; validationResult.ErrorMessage = "Distribution Point Name Is Not Valid"; return(validationResult); } if (isNewDistributionPoint) { var primaryDp = GetPrimaryDistributionPoint(); if (primaryDp != null && Convert.ToBoolean(distributionPoint.IsPrimary)) { validationResult.Success = false; validationResult.ErrorMessage = "There Can Only Be One Primary Distribution Point"; return(validationResult); } if (_uow.DistributionPointRepository.Exists(h => h.DisplayName == distributionPoint.DisplayName)) { validationResult.Success = false; validationResult.ErrorMessage = "This Distribution Point Already Exists"; return(validationResult); } } else { var originalDistributionPoint = _uow.DistributionPointRepository.GetById(distributionPoint.Id); var primaryDp = GetPrimaryDistributionPoint(); if (primaryDp != null) { if ((primaryDp.Id != distributionPoint.Id) && distributionPoint.IsPrimary == 1) { validationResult.Success = false; validationResult.ErrorMessage = "There Can Only Be One Primary Distribution Point"; return(validationResult); } } if (originalDistributionPoint.DisplayName != distributionPoint.DisplayName) { if (_uow.DistributionPointRepository.Exists(h => h.DisplayName == distributionPoint.DisplayName)) { validationResult.Success = false; validationResult.ErrorMessage = "This Distribution Point Already Exists"; return(validationResult); } } } return(validationResult); }