public ActionResultDTO UpdateClusterGroup(ClusterGroupEntity clusterGroup) { var s = GetClusterGroup(clusterGroup.Id); if (s == null) { return new ActionResultDTO { ErrorMessage = "Cluster Group Not Found", Id = 0 } } ; var validationResult = ValidateClusterGroup(clusterGroup, false); var actionResult = new ActionResultDTO(); if (validationResult.Success) { _uow.ClusterGroupRepository.Update(clusterGroup, clusterGroup.Id); _uow.Save(); actionResult.Success = true; actionResult.Id = clusterGroup.Id; } else { actionResult.ErrorMessage = validationResult.ErrorMessage; } return(actionResult); }
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); }
public ActionResultDTO Put(int id, ClusterGroupEntity clusterGroup) { clusterGroup.Id = id; var result = _clusterGroupServices.UpdateClusterGroup(clusterGroup); if (result == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } return(result); }
public ClusterGroupEntity GetClusterGroup(int computerId) { ClusterGroupEntity cg = null; var cgServices = new ClusterGroupServices(); var computer = GetComputer(computerId); if (computer.ClusterGroupId != -1) { cg = cgServices.GetClusterGroup(computer.ClusterGroupId); return(cg ?? cgServices.GetDefaultClusterGroup()); } if (computer.RoomId != -1) { var room = new RoomServices().GetRoom(computer.RoomId); if (room != null) { if (room.ClusterGroupId != -1) { cg = cgServices.GetClusterGroup(room.ClusterGroupId); return(cg ?? cgServices.GetDefaultClusterGroup()); } } } if (computer.BuildingId != -1) { var building = new BuildingServices().GetBuilding(computer.BuildingId); if (building != null) { if (building.ClusterGroupId != -1) { cg = cgServices.GetClusterGroup(building.ClusterGroupId); return(cg ?? cgServices.GetDefaultClusterGroup()); } } } if (computer.SiteId != -1) { var site = new SiteServices().GetSite(computer.SiteId); if (site != null) { if (site.ClusterGroupId != -1) { cg = cgServices.GetClusterGroup(site.ClusterGroupId); return(cg ?? cgServices.GetDefaultClusterGroup()); } } } return(cgServices.GetDefaultClusterGroup()); }
public ActionResultDTO Put(int id, ClusterGroupEntity tObject) { Request.Method = Method.PUT; Request.AddJsonBody(tObject); Request.Resource = string.Format("api/{0}/Put/{1}", Resource, id); var response = _apiRequest.Execute <ActionResultDTO>(Request); if (response.Id == 0) { response.Success = false; } return(response); }
public ActionResultDTO AddClusterGroup(ClusterGroupEntity clusterGroup) { var actionResult = new ActionResultDTO(); var validationResult = ValidateClusterGroup(clusterGroup, true); if (validationResult.Success) { _uow.ClusterGroupRepository.Insert(clusterGroup); _uow.Save(); actionResult.Success = true; actionResult.Id = clusterGroup.Id; } else { actionResult.ErrorMessage = validationResult.ErrorMessage; } return(actionResult); }
public ActionResultDTO Post(ClusterGroupEntity clusterGroup) { return(_clusterGroupServices.AddClusterGroup(clusterGroup)); }
protected void btnAddCluster_OnClick(object sender, EventArgs e) { RequiresAuthorization(AuthorizationStrings.UpdateAdmin); var clusterGroup = new ClusterGroupEntity { Name = txtClusterName.Text, Default = chkDefault.Checked ? 1 : 0 }; var result = Call.ClusterGroupApi.Post(clusterGroup); if (result.Success) { var listOfServers = new List <ClusterGroupServerEntity>(); foreach (GridViewRow row in gvServers.Rows) { var cb = (CheckBox)row.FindControl("chkSelector"); if (!cb.Checked) { continue; } var cbTftp = (CheckBox)row.FindControl("chkTftp"); var cbMulticast = (CheckBox)row.FindControl("chkMulticast"); var dataKey = gvServers.DataKeys[row.RowIndex]; if (dataKey == null) { continue; } var clusterGroupServer = new ClusterGroupServerEntity(); clusterGroupServer.ClusterGroupId = result.Id; clusterGroupServer.ServerId = Convert.ToInt32(dataKey.Value); if (cbTftp.Checked) { clusterGroupServer.TftpRole = 1; } if (cbMulticast.Checked) { clusterGroupServer.MulticastRole = 1; } listOfServers.Add(clusterGroupServer); } Call.ClusterGroupServerApi.Post(listOfServers); var listOfDps = new List <ClusterGroupDistributionPointEntity>(); foreach (GridViewRow row in gvDps.Rows) { var cb = (CheckBox)row.FindControl("chkSelector"); if (!cb.Checked) { continue; } var dataKey = gvDps.DataKeys[row.RowIndex]; if (dataKey == null) { continue; } var clusterGroupDistributionPoint = new ClusterGroupDistributionPointEntity(); clusterGroupDistributionPoint.ClusterGroupId = result.Id; clusterGroupDistributionPoint.DistributionPointId = Convert.ToInt32(dataKey.Value); listOfDps.Add(clusterGroupDistributionPoint); } Call.ClusterGroupDistributionPointApi.Post(listOfDps); EndUserMessage = "Successfully Created Cluster Group"; Response.Redirect("~/views/admin/cluster/editcluster.aspx?cat=sub1&clusterid=" + result.Id); } else { EndUserMessage = result.ErrorMessage; } }
protected void btnUpdateCluster_OnClick(object sender, EventArgs e) { RequiresAuthorization(AuthorizationStrings.UpdateAdmin); var clusterGroup = new ClusterGroupEntity { Id = ClusterGroup.Id, Name = txtClusterName.Text, Default = chkDefault.Checked ? 1 : 0 }; var result = Call.ClusterGroupApi.Put(clusterGroup.Id, clusterGroup); if (result.Success) { var listOfServers = new List <ClusterGroupServerEntity>(); foreach (GridViewRow row in gvServers.Rows) { var cb = (CheckBox)row.FindControl("chkSelector"); if (!cb.Checked) { continue; } var cbImage = (CheckBox)row.FindControl("chkImage"); var cbTftp = (CheckBox)row.FindControl("chkTftp"); var cbMulticast = (CheckBox)row.FindControl("chkMulticast"); var dataKey = gvServers.DataKeys[row.RowIndex]; if (dataKey == null) { continue; } var clusterGroupServer = new ClusterGroupServerEntity(); clusterGroupServer.ClusterGroupId = result.Id; clusterGroupServer.ServerId = Convert.ToInt32(dataKey.Value); if (cbTftp.Checked) { clusterGroupServer.TftpRole = 1; } if (!cbTftp.Visible) { clusterGroupServer.TftpRole = 0; } if (cbMulticast.Checked) { clusterGroupServer.MulticastRole = 1; } if (!cbMulticast.Visible) { clusterGroupServer.MulticastRole = 0; } listOfServers.Add(clusterGroupServer); } if (listOfServers.Count == 0) { listOfServers.Add(new ClusterGroupServerEntity { ClusterGroupId = ClusterGroup.Id, ServerId = -2 }); } Call.ClusterGroupServerApi.Post(listOfServers); var listOfDps = new List <ClusterGroupDistributionPointEntity>(); foreach (GridViewRow row in gvDps.Rows) { var cb = (CheckBox)row.FindControl("chkSelector"); if (!cb.Checked) { continue; } var dataKey = gvDps.DataKeys[row.RowIndex]; if (dataKey == null) { continue; } var clusterGroupDistributionPoint = new ClusterGroupDistributionPointEntity(); clusterGroupDistributionPoint.ClusterGroupId = result.Id; clusterGroupDistributionPoint.DistributionPointId = Convert.ToInt32(dataKey.Value); listOfDps.Add(clusterGroupDistributionPoint); } if (listOfDps.Count == 0) { listOfDps.Add(new ClusterGroupDistributionPointEntity { ClusterGroupId = ClusterGroup.Id, DistributionPointId = -2 }); } Call.ClusterGroupDistributionPointApi.Post(listOfDps); EndUserMessage = "Successfully Updated Cluster Group"; } else { EndUserMessage = result.ErrorMessage; } }