protected override IBirthdayEvent OnExecute() { this.Trace.TraceDebug((long)this.GetHashCode(), "Updating birthday for contact"); this.Result = new BirthdayEventCommandResult(); IBirthdayEventInternal birthdayEventInternal = this.BirthdayEvent as IBirthdayEventInternal; if (birthdayEventInternal == null) { throw new ArgumentException("Was not expecting a null internal birthday event"); } IBirthdayContactInternal birthdayContactInternal = this.BirthdayContact as IBirthdayContactInternal; if (birthdayContactInternal == null) { throw new ArgumentException("Was not expecting a null internal birthday contact"); } if (UpdateBirthdayEventForContact.ShouldEventBeUpdated(birthdayEventInternal, birthdayContactInternal)) { this.Scope.BirthdayEventDataProvider.Delete(birthdayEventInternal.StoreId, DeleteItemFlags.HardDelete); this.Result.DeletedEvents.Add(this.BirthdayEvent); this.Result.MergeWith(this.Scope.CreateBirthdayEventForContact(this.BirthdayContact)); } PersonId personId = birthdayEventInternal.PersonId; if (personId != null && !personId.Equals(birthdayContactInternal.PersonId)) { IEnumerable <IBirthdayContact> linkedContacts = this.Scope.ParentScope.ParentScope.Contacts.GetLinkedContacts(personId); this.Result.MergeWith(this.Scope.UpdateBirthdaysForLinkedContacts(linkedContacts)); } return(this.Result.CreatedEvents.FirstOrDefault <IBirthdayEvent>()); }
protected override IBirthdayEvent OnExecute() { this.Trace.TraceDebug((long)this.GetHashCode(), "Updating birthdays for linked contacts"); this.Result = new BirthdayEventCommandResult(); IEnumerable <IGrouping <ExDateTime?, IBirthdayContact> > enumerable = from eachContact in this.LinkedContacts group eachContact by eachContact.Birthday; foreach (IGrouping <ExDateTime?, IBirthdayContact> grouping in enumerable) { bool flag = false; foreach (IBirthdayContact birthdayContact in grouping) { if (birthdayContact.Birthday != null && !birthdayContact.ShouldHideBirthday && !flag) { flag = true; IBirthdayEvent birthdayEvent = this.FindBirthdayEventForContact(birthdayContact); this.Result.MergeWith((birthdayEvent == null) ? this.Scope.CreateBirthdayEventForContact(birthdayContact) : this.Scope.UpdateBirthdayEventForContact(birthdayEvent, birthdayContact)); } else { this.Result.MergeWith(this.Scope.DeleteBirthdayEventForContact(birthdayContact)); } } } return(null); }
public BirthdayEventCommandResult ExecuteAndGetResult() { BirthdayEventCommandResult birthdayEventCommandResult = new BirthdayEventCommandResult(); IBirthdayEvent birthdayEvent = base.Execute(null); if (birthdayEvent != null) { birthdayEventCommandResult.CreatedEvents.Add(birthdayEvent); } return(birthdayEventCommandResult); }
public void MergeWith(BirthdayEventCommandResult resultOf) { this.CreatedEvents.AddRange(resultOf.CreatedEvents); this.DeletedEvents.AddRange(resultOf.DeletedEvents); }