private void Handle(CaseFileAddedEvent caseFileAddedEvent)
        {
            if (string.IsNullOrWhiteSpace(caseFileAddedEvent.Name))
            {
                throw new AggregateValidationException(new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("validation", "name must be specified")
                });
            }

            if (string.IsNullOrWhiteSpace(caseFileAddedEvent.Description))
            {
                throw new AggregateValidationException(new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("validation", "description must be specified")
                });
            }

            AggregateId    = caseFileAddedEvent.AggregateId;
            FileId         = caseFileAddedEvent.FileId;
            Name           = caseFileAddedEvent.Name;
            Description    = caseFileAddedEvent.Description;
            CreateDateTime = caseFileAddedEvent.CreateDateTime;
            Owner          = caseFileAddedEvent.Owner;
            Payload        = caseFileAddedEvent.Payload;
            Version        = caseFileAddedEvent.Version;
            Status         = CaseFileStatus.Edited;
        }
        public static CaseFileAggregate New(string name, string description, int version, string owner, string payload = null, string fileId = null)
        {
            var result = new CaseFileAggregate();

            lock (result.DomainEvents)
            {
                if (string.IsNullOrWhiteSpace(fileId))
                {
                    fileId = Guid.NewGuid().ToString();
                }

                var evt = new CaseFileAddedEvent(Guid.NewGuid().ToString(), BuildCaseFileIdentifier(fileId, version), version, fileId, name, description, DateTime.UtcNow, owner, payload);
                result.Handle(evt);
                result.DomainEvents.Add(evt);
            }

            return(result);
        }