internal void Handle(DeleteTargetFromCampaign request) { var resp = new DeleteTargetFromCampaignResponse() { swlr = SwlResult.GENERAL_FAIL }; using (var dbConn = DatabaseManager.DbConn()) { dbConn.BeginTransaction(this); var campaignId = BplIdentity.Empty; foreach (var targetId in request.TargetIds) { var ti = dbConn.ExecuteBpl(new CampaignTargetGetById { TargetId = targetId }); if (ti == null) { Log.Error("Target with Id {0} not found in database", targetId); resp.swlr = SwlResult.NOT_FOUND; goto Exit; } if (campaignId.IsEmpty) { campaignId = ti.CampaignId; } else { if (campaignId != ti.CampaignId) { Log.Error("Detected targets from different campaigns ({0} != {1}", campaignId, ti.CampaignId); resp.swlr = SwlResult.INVALID_DATA; goto Exit; } } dbConn.ExecuteBpl(new CampaignTargetDelete { TargetId = targetId }); } resp.swlr = LogisticsHelpers.CampaignCheckStatus(dbConn, campaignId); if (resp.swlr != SwlResult.OK) { goto Exit; } dbConn.CommitTransaction(); } resp.swlr = SwlResult.OK; Exit: Reply(resp); }
private void _btnRemoveTargetOnClick(object sender, EventArgs e) { if (_isNew) { foreach (var li in listTargets.SelectedItems) { _campaignTargetsInfo.Remove(((TargetListItem)li).Target); } _refreshList(); return; } var b = MessageBox.Show("Do you really want to remove selected devices\r\npossible it will change status of the campaign", "Remove devices from the campaign", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (b != DialogResult.Yes) { return; } var req = new DeleteTargetFromCampaign(); req.TargetIds = listTargets.SelectedItems.Cast<TargetListItem>().Select(i => i.Target.TargetId).ToArray(); //var ids = new List<BplIdentity>(); //foreach (var li in listTargets.SelectedItems) { // ids.Add(((TargetListItem)li).Target.TargetId); //} //req.TargetIds = ids.ToArray(); SendRequest(req); }