private void Cancel(string userName, CampaignState newState, Campaign context) { if (context.State == CampaignState.Cancelled) { throw new InvalidOperationException("Can't cancel a campaign that is already cancelled."); } if (context.State == CampaignState.Completed) { throw new InvalidOperationException("Can't cancel a campaign once it has completed."); } string message = String.Format("{0} cancelled {1} campaign {2}", userName, context.State.Name, this.Name); AdvertiserNotificationService.NotifyAdvertiser(context.Advertiser, message); context.State = newState; context.LastUpdatedBy = userName; }
private void Approve(string userName, CampaignState newState) { if (this.State == CampaignState.Approved) { throw new InvalidOperationException("Can't approve a campaign once it has already been approved."); } if (this.State == CampaignState.Completed) { throw new InvalidOperationException("Can't approve a campaign once it has completed."); } if (this.State == CampaignState.Active) { throw new InvalidOperationException("Can't approve a campaign once it is active."); } string message = String.Format("{0} approved {1} campaign {2}", userName, this.State.Name, this.Name); AdvertiserNotificationService.NotifyAdvertiser(this.Advertiser, message); this.State = newState; this.LastUpdatedBy = userName; }
public void UpdateStatus(string newStatus, string userName) { CampaignState newState = CampaignState.ForStatus(newStatus); if (newState == CampaignState.Cancelled) { Cancel(userName, newState); } else if (newState == CampaignState.Pending) { MarkPending(); } else if (newState == CampaignState.Approved) { Approve(userName, newState); } else if (newState == CampaignState.Active) { } else if (newState == CampaignState.Completed) { } }