public virtual void Add(TEvent theEvent) { if (string.IsNullOrEmpty(theEvent.EventId)) { theEvent.EventId = Guid.NewGuid().ToString(); } if (theEvent.IsFinal) { theEvent.Created = DateTime.Now; Latest = theEvent; History.Add(theEvent); Drafts.Clear(); return; } else { theEvent.Created = theEvent.Created == null ? DateTime.Now : theEvent.Created; var usersDraft = Drafts.SingleOrDefault(draft => draft.UserId == theEvent.UserId); if (usersDraft != null) { Drafts.Remove(usersDraft); Drafts.Add(theEvent); return; } Drafts.Add(theEvent); } }
public override void Add(OtherEvent theEvent) { if (string.IsNullOrEmpty(theEvent.EventId)) { theEvent.EventId = Guid.NewGuid().ToString(); } if (theEvent.IsFinal) { theEvent.Created = DateTime.Now; Latest = theEvent; History.Add(theEvent); var draft = Drafts.SingleOrDefault(d => d.EventId == theEvent.EventId); if (draft != null) { Drafts.Remove(draft); } return; } else { theEvent.Created = theEvent.Created == null ? DateTime.Now : theEvent.Created; var userHasDraft = Drafts.Any(draft => draft.UserId == theEvent.UserId); if (userHasDraft) { var usersDraft = Drafts.SingleOrDefault(draft => draft.EventId == theEvent.EventId); if (usersDraft == null) { throw new ArgumentException(nameof(theEvent.EventId)); } Drafts.Remove(usersDraft); Drafts.Add(theEvent); return; } Drafts.Add(theEvent); } }