protected bool Equals(ActivityDocument other) { return FileId == other.FileId && ImageId == other.ImageId && string.Equals(ModeText, other.ModeText) && Visible.Equals(other.Visible) && string.Equals(Title, other.Title); }
public void Handle(CreateActivityDocument command) { if (command == null) { throw new ArgumentNullException("command"); } var values = command.ActivityValues; if (values == null) { if (command.Mode.HasValue) { var modeText = command.Mode.Value.AsSentenceFragment(); values = _entities.Get <ActivityValues>() .Single(x => x.ActivityId == command.ActivityId && x.ModeText == modeText); } else { values = _entities.Get <ActivityValues>() .Single(x => x.ActivityId == command.ActivityId && x.ModeText == x.Activity.ModeText); } } var path = command.Path; if (string.IsNullOrWhiteSpace(path)) { path = string.Format(ActivityDocument.PathFormat, values.ActivityId, Guid.NewGuid()); _binaryData.Put(path, command.Content, true); } var activityDocument = new ActivityDocument { ActivityValues = values, Title = command.Title, FileName = command.FileName, MimeType = command.MimeType, Path = path, Length = command.Length.HasValue ? (int)command.Length.Value : command.Content.Length, CreatedByPrincipal = command.Impersonator == null ? command.Principal.Identity.Name : command.Impersonator.Identity.Name, }; if (command.EntityId.HasValue && command.EntityId != Guid.Empty) { activityDocument.EntityId = command.EntityId.Value; } values.Documents.Add(activityDocument); // do NOT update activity here as it throws concurrency exceptions // when users upload multiple documents at once _entities.Create(activityDocument); if (!command.NoCommit) { try { _entities.SaveChanges(); command.CreatedActivityDocument = _detachedEntities.Query <ActivityDocument>() .Single(x => x.RevisionId == activityDocument.RevisionId); } catch { _binaryData.Delete(activityDocument.Path); throw; } } else { command.CreatedActivityDocument = activityDocument; } }