public void DeleteUser() { // impersonate thread if (threadUserId != -1) { SecurityContext.SetThreadPrincipal(threadUserId); } // get user details UserInfo user = UserController.GetUserInternally(userId); // place log record TaskManager.StartTask(taskId, "USER", "DELETE", user.Username); TaskManager.ItemId = userId; try { // delete user packages List <PackageInfo> packages = PackageController.GetMyPackages(userId); // delete user packages synchronously if (packages.Count > 0) { PackageAsyncWorker packageWorker = new PackageAsyncWorker(); packageWorker.UserId = SecurityContext.User.UserId; packageWorker.Packages = packages; // invoke worker packageWorker.DeletePackagesServiceItems(); } // delete user from database DataProvider.DeleteUser(SecurityContext.User.UserId, userId); } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
public static int DeletePackages(List<PackageInfo> packages) { // delete packages asynchronously PackageAsyncWorker packageWorker = new PackageAsyncWorker(); packageWorker.UserId = SecurityContext.User.UserId; packageWorker.Packages = packages; // invoke worker packageWorker.DeletePackagesServiceItemsAsync(); return 0; }
public static int ChangePackagesStatus(List<PackageInfo> packages, PackageStatus status, bool async) { int statusId = (int)status; List<PackageInfo> changedPackages = new List<PackageInfo>(); foreach (PackageInfo p in packages) { // get package details PackageInfo package = GetPackage(p.PackageId); if (package != null && package.StatusId != statusId) { bool currEnabled = (package.StatusId == (int)PackageStatus.Active); bool enabled = (statusId == (int)PackageStatus.Active); // change package status package.StatusId = statusId; // save package UpdatePackage(package); // add to the list of affected packages if (currEnabled != enabled) changedPackages.Add(package); } } // change service items state asynchronously PackageAsyncWorker packageWorker = new PackageAsyncWorker(); packageWorker.UserId = SecurityContext.User.UserId; packageWorker.Packages = changedPackages; packageWorker.ItemsStatus = status; // invoke worker if (async) packageWorker.ChangePackagesServiceItemsStateAsync(); else packageWorker.ChangePackagesServiceItemsState(); return 0; }
public void DeleteUser() { // impersonate thread if (threadUserId != -1) SecurityContext.SetThreadPrincipal(threadUserId); // get user details UserInfo user = UserController.GetUserInternally(userId); // place log record TaskManager.StartTask(taskId, "USER", "DELETE", user.Username); TaskManager.ItemId = userId; try { // delete user packages List<PackageInfo> packages = PackageController.GetMyPackages(userId); // delete user packages synchronously if (packages.Count > 0) { PackageAsyncWorker packageWorker = new PackageAsyncWorker(); packageWorker.UserId = SecurityContext.User.UserId; packageWorker.Packages = packages; // invoke worker packageWorker.DeletePackagesServiceItems(); } // delete user from database DataProvider.DeleteUser(SecurityContext.User.UserId, userId); } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }