public void MoveUpPackagePriority(Package iPackage) { if (iPackage == null) { throw new Exception("La tâche est nulle"); } if (iPackage.Priority != null) { if (iPackage.Priority < 0) { throw new Exception("La priorité doit être positive"); } if (iPackage.Priority == 1) { throw new Exception("La priorité est déjà maximale"); } } using (var ts = new TransactionScope()) { var thePackage = DBReleaseDataService.GetPackageById(iPackage.PackageId); int? thePriority = 1; T_E_Package previousPackage = null; if (thePackage.Priority != null) { //package thePriority = thePackage.Priority - 1; //package précédent previousPackage = DBReleaseDataService.GetSingleOrDefault <T_E_Package>(x => x.Priority == iPackage.Priority - 1); previousPackage.Priority++; DBReleaseDataService.Update(previousPackage); } else { previousPackage = DBReleaseDataService.GetSingleOrDefault <T_E_Package>(x => x.Priority == 1); var packageWithPriority = DBReleaseDataService.GetList <T_E_Package>(x => x.Priority != null && x.Priority != 1).Enum().OrderByDescending(x => x.Priority).Enum().Select(x => x.Convert()).Enum().ToList(); foreach (var packagePriority in packageWithPriority.Enum()) { MoveDownPackagePriority(packagePriority); } } thePackage.Priority = thePriority; DBReleaseDataService.Update(thePackage); ts.Complete(); } }
public void SetPackagePriority(Package iPackage, int iNewPriority) { if (iPackage == null) { throw new Exception("Le package est nulle"); } if (iPackage.Priority < 0) { throw new Exception("La priorité doit être positive"); } if (iPackage.Priority == iNewPriority) { return; } using (var ts = new TransactionScope()) { var thePackage = DBReleaseDataService.GetPackageById(iPackage.PackageId); List <T_E_Package> upPriorityPackages = null; if (iNewPriority < thePackage.Priority) { upPriorityPackages = DBReleaseDataService.GetList <T_E_Package>(null).Where(x => x.Priority >= iNewPriority).ToList(); } else { upPriorityPackages = DBReleaseDataService.GetList <T_E_Package>(null).Where(x => x.Priority > iNewPriority).ToList(); } //enleve le package concerné si présent upPriorityPackages.RemoveAll(x => x.PackageId == thePackage.PackageId); //incrémente toutes les priorités foreach (var item in upPriorityPackages) { item.Priority = item.Priority + 1; DBReleaseDataService.Update(item); } //the package thePackage.Priority = iNewPriority; DBReleaseDataService.Update(thePackage); //Nettoyage des trous FillGapPackagePriority(); ts.Complete(); } }
public void MoveDownPackagePriority(Package iPackage) { if (iPackage == null) { throw new Exception("La tâche est nulle"); } if (iPackage.Priority < 0) { throw new Exception("La priorité doit être positive"); } using (var ts = new TransactionScope()) { var thePackage = DBReleaseDataService.GetPackageById(iPackage.PackageId); T_E_Package followingPackage = null; int? thePriority; if (thePackage.Priority != null) { thePriority = thePackage.Priority + 1; followingPackage = DBReleaseDataService.GetSingleOrDefault <T_E_Package>(x => x.Priority == iPackage.Priority + 1); } else { var lastPriority = DBReleaseDataService.GetQuery <T_E_Package>(null).Max(x => x.Priority); if (lastPriority == null) { thePriority = 1; } else { thePriority = lastPriority + 1; } } thePackage.Priority = thePriority; DBReleaseDataService.Update(thePackage); if (followingPackage != null) { followingPackage.Priority -= 1; DBReleaseDataService.Update(followingPackage); } ts.Complete(); } }
public Package GetPackageById(long iPackageId, GranularityEnum iGranularity) { if (iPackageId < 1) { throw new Exception("L'id du package n'est pas valide"); } var thePackage = DBReleaseDataService.GetPackageById(iPackageId).Convert(); if (iGranularity == GranularityEnum.Full) { //Deployement thePackage.Deployements = GetDeployementByPackageId(iPackageId); //MainTask thePackage.MainTasks = GetMaintaskListByPackageId(iPackageId).Enum().Where(x => x.Status != MainTaskStatusEnum.Canceled).Enum().ToList(); //ProjectTask thePackage.SubTasks = new List <SubTask>(); foreach (var mainTaskItem in thePackage.MainTasks.Enum()) { mainTaskItem.SubTasks = GetSubTaskByMainTaskId(mainTaskItem.MainTaskId); thePackage.SubTasks.AddRange(mainTaskItem.SubTasks); } } else if (iGranularity == GranularityEnum.Partial1) { //MainTask thePackage.MainTasks = GetMaintaskListByPackageId(iPackageId).Enum().Where(x => x.Status != MainTaskStatusEnum.Canceled).Enum().ToList(); //ProjectTask thePackage.SubTasks = new List <SubTask>(); foreach (var mainTaskItem in thePackage.MainTasks.Enum()) { mainTaskItem.SubTasks = GetSubTaskByMainTaskId(mainTaskItem.MainTaskId); thePackage.SubTasks.AddRange(mainTaskItem.SubTasks); } } return(thePackage); }