/// <summary> /// Create Topic /// </summary> /// <param name="title">Title</param> /// <param name="message">Message</param> /// <param name="from">From</param> /// <param name="to">To</param> /// <param name="attachments">Attachments</param> public int CreateTopic(string title, string message, string from, string to, IEnumerable <TopicAttachmentInfo> attachments) { // if to is not empty then this is a direct message // otherwise get the to users from followers if (string.IsNullOrWhiteSpace(to)) { to = GetBroadcastUsers(from); } var users = to + ";" + from; // topic visible to sender (from) as well var usersToCopy = ParseUsers.GetListUsersName(_usersService, users); using (var uofw = new FlowTasksUnitOfWork()) { var topic = new Core.Topic { Title = title, LastChanged = DateTime.Now }; uofw.Topics.Insert(topic); CreateMessage(uofw, topic, true, message, from, to, attachments, usersToCopy); uofw.Commit(); return(topic.TopicId); } }
/// <summary> /// Create Message /// </summary> /// <param name="uofw">FlowTasksUnitOfWork</param> /// <param name="topic">Topic</param> /// <param name="isTopic">Is Topic</param> /// <param name="message">Message</param> /// <param name="from">From</param> /// <param name="to">To</param> /// <param name="attachments">Attachments</param> /// <param name="usersToCopy">Users To Copy</param> private static void CreateMessage(FlowTasksUnitOfWork uofw, Core.Topic topic, bool isTopic, string message, string from, string to, IEnumerable <TopicAttachmentInfo> attachments, IEnumerable <string> usersToCopy) { var newMessage = new TopicMessage { Message = message, IsTopic = isTopic, From = from, To = to, When = DateTime.Now, Topic = topic }; uofw.TopicMessages.Insert(newMessage); var statusNewStr = TopicStatusType.New.ToString(); var statusReadStr = TopicStatusType.Read.ToString(); var statusNew = uofw.TopicStatuses.First(s => s.Status == statusNewStr); var statusRead = uofw.TopicStatuses.First(s => s.Status == statusReadStr); foreach (var u in usersToCopy) { var status = string.Equals(u, from, StringComparison.OrdinalIgnoreCase) ? statusRead : statusNew; uofw.TopicUsers.Insert(new TopicUser { TopicMessage = newMessage, User = u, TopicStatus = status }); } if (attachments != null) { foreach (var a in attachments) { uofw.TopicAttachments.Insert(new TopicAttachment { FileName = a.FileName, OidDocument = a.DocumentOid, TopicMessage = newMessage }); } } }