protected override Task <bool> InsertMessage(MessageAggregateState state) { if (state == null) { throw new ArgumentNullException(nameof(state)); } MessageContext.Instance().Messages.Add(state.ToModel()); return(Task.FromResult(true)); }
public static MessageAggregateState ToDomain(this Message message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } var result = new MessageAggregateState { Content = message.Content, IsPinned = message.IsPinned, Status = (MessageStatus)message.Status, Sender = message.Sender.Id, CreateDateTime = message.CreateDateTime, Attachments = new List <AttachmentState>(), HashTags = new List <string>() }; if (message.Attachments != null) { result.Attachments = message.Attachments.Select(a => new AttachmentState { Type = (AttachmentTypes)a.Type, Url = a.Url }); } if (message.HashTags != null) { result.HashTags = message.HashTags.Select(h => h.Value); } if (message.Likes != null) { result.Likes = message.Likes.Select(l => new LikeState { CreateDateTime = l.CreateDateTime, Subject = l.User.Id }); } if (message.Shares != null) { result.Shares = message.Shares.Select(s => new ShareState { CreateDateTime = s.CreateDateTime, Subject = s.User.Id }); } return(result); }
protected virtual Task <bool> InsertMessage(MessageAggregateState state) { return(Task.FromResult(true)); }
public static Message ToModel(this MessageAggregateState message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } var result = new Message { Content = message.Content, IsPinned = message.IsPinned, Status = (int)message.Status, Sender = new User { Id = message.Sender }, CreateDateTime = message.CreateDateTime, Attachments = new List <Attachment>(), HashTags = new List <HashTag>() }; if (message.Attachments != null) { result.Attachments = message.Attachments.Select(a => new Attachment { Type = (int)a.Type, Url = a.Url }); } if (message.HashTags != null) { result.HashTags = message.HashTags.Select(h => new HashTag { Value = h }); } if (message.Likes != null) { result.Likes = message.Likes.Select(l => new Like { CreateDateTime = l.CreateDateTime, User = new User { Id = l.Subject } }); } if (message.Shares != null) { result.Shares = message.Shares.Select(s => new Share { CreateDateTime = s.CreateDateTime, User = new User { Id = s.Subject } }); } return(result); }