public bool SubscribeTopic(string userId, string topicName, ref string errorMessage) { User user; try { user = UserStorage.GetUserByID(userId); if (user == null) { errorMessage = "Invalid UserID!"; return(false); } if (ColTopics.ContainsKey(topicName)) { user.SubscribeTopic(topicName); Console.WriteLine("[INFO - REPOSITORY] : Topic Subscribed: [{0}] for UserID: [{1}]", topicName, userId); return(true); } else { errorMessage = "Invalid TopicName!"; return(false); } } catch (Exception ex) { Log.Error(ex.Message); return(false); } }
public List <CSTaskDTO> GetSubscribedTasksbyUserID(string userID) { List <string> subscribedTopics = new List <string>(); List <CSTaskDTO> subscribedTasks = new List <CSTaskDTO>(); Topic auxTopic; CSTask task; User user; try { Console.WriteLine("[INFO - REPOSITORY] : Fetching Subscribed Tasks"); user = UserStorage.GetUserByID(userID); if (user != null) { subscribedTopics = user.SubscribedTopics; foreach (string topicName in subscribedTopics) { if (ColTopics.ContainsKey(topicName)) { auxTopic = ColTopics[topicName]; foreach (string taskId in auxTopic.ListOfTaskIDs) { //if is a subscribed task but not created by the user task = TaskStorage.GetTaskByID(taskId); if (task != null && !user.MyTasks.Contains(taskId)) { subscribedTasks.Add(task.ToDTO()); } } } else { return(null); } } return(subscribedTasks); } else { return(null); } } catch (Exception ex) { Log.Error(ex.Message); return(null); } }
public List <CSTaskDTO> GetSubscribedTasksbyTopic(string userID, string topicName, ref string errorMessage) { List <string> subscribedTopics = new List <string>(); List <CSTaskDTO> subscribedTasks = new List <CSTaskDTO>(); Topic auxTopic; CSTask task; try { Console.WriteLine("[INFO - REPOSITORY] : Fetching Subscribed Tasks For UserID: [{0}] and TopicName: [{1}]", userID, topicName); if (UserStorage.GetUserByID(userID) == null) { errorMessage = "Invalid UserID!"; return(null); } if (ColTopics.ContainsKey(topicName)) { auxTopic = ColTopics[topicName]; foreach (string taskId in auxTopic.ListOfTaskIDs) { task = TaskStorage.GetTaskByID(taskId); if (task != null) { subscribedTasks.Add(task.ToDTO()); } } return(subscribedTasks); } else { errorMessage = "Invalid Topic Name!"; return(null); } } catch (Exception ex) { Log.Error(ex.Message); return(null); } }
private bool SaveTask(CSTaskDTO task, out string taskID) { taskID = null; Topic topic; try { if (task == null || task.TopicName == null) { Log.Error("Task or Topic IS NULL"); return(false); } if (!TaskStorage.CreateTask(task)) { return(false); } taskID = task.TaskID; Log.DebugFormat("Generated TaskID: [{0}]", taskID); Log.Debug("Task Saved with sucess!"); //save topic if (ColTopics.ContainsKey(task.TopicName)) { ColTopics[task.TopicName].ListOfTaskIDs.Add(task.TaskID); } //topico nao existe else { topic = new Topic(task.TopicName); topic.ListOfTaskIDs.Add(task.TaskID); ColTopics.Add(task.TopicName, topic); } return(true); } catch (Exception ex) { Log.Error(ex.Message); return(false); } }
public bool GetTasksByTopicName(out List <GetTasksDTO> listTaskDTO, string topicName) { Topic topic; GetTasksDTO taskDTO = null; CSTask task; listTaskDTO = null; try { if (!ColTopics.TryGetValue(topicName, out topic)) { Log.ErrorFormat("Invalid Topic Name: [{0}]", topicName); return(false); } listTaskDTO = new List <GetTasksDTO>(); foreach (string taskID in topic.ListOfTaskIDs) { taskDTO = new GetTasksDTO(); task = TaskStorage.GetTaskByID(taskID); if (task == null) { Log.ErrorFormat("TaskID: [{0}] already does not exist!. Going to remove from Topics.", taskID); topic.ListOfTaskIDs.Remove(taskID); } taskDTO.TaskID = task.TaskID; taskDTO.TaskName = task.Name; listTaskDTO.Add(taskDTO); } return(true); } catch (Exception ex) { Log.Error(ex); return(false); } }