public AddPresenter(IAddTaskView view, IToDoListRepository repository) { this.view = view; this.repository = repository; view.Add += AddItem; }
/// <summary> /// Extracts TaskItem input data from a IAddTaskView and creates a new TaskItem for the /// application. /// </summary> /// <param name="view"> /// Where new TaskItem info was inputted /// </param> public void CreateTask(IAddTaskView view) { //map the view's notification frequency type string to an enum value NotificationFrequencyType notificationFrequencyType = frequenctTypeStrMap.Where(x => x.Value == view.FrequencyType).First().Key; //create input for use-case from data of the view CreateTaskInput input = new CreateTaskInput { Title = view.Title, Description = view.Description, StartTime = view.StartTime, R = view.Color.R, G = view.Color.G, B = view.Color.B, NotificationFrequencyType = notificationFrequencyType, CustomNotificationFrequency = view.CustomFrequency }; //create UseCase instance and assign input structure to its input port var uc = taskSchedulerApplication.NewCreateTaskUseCase(); //run the use case CreateTaskOutput output = uc.Execute(input); if (output.Success) { //get the taskItemDTO returned creatd by the executed usecase TaskItemDTO taskDTO = output.TaskItemDTO; //get a string representation of the taskDTO's notification frequency type string frequencyTypeStr = frequenctTypeStrMap[taskDTO.NotificationFrequencyType]; //convert the taskDTO's rgb color to a Windows brush SolidColorBrush colorBrush = new SolidColorBrush(Windows.UI.Color.FromArgb(255, taskDTO.R, taskDTO.G, taskDTO.B)); //create task item model from taskDTO TaskItemModel newTaskItemModel = new TaskItemModel() { Id = taskDTO.Id, Title = taskDTO.Title, Description = taskDTO.Description, StartTime = taskDTO.StartTime, FrequencyType = frequencyTypeStr, NotificationFrequency = taskDTO.CustomNotificationFrequency, Color = colorBrush }; //fire the TaskCreated event OnTaskCreated(newTaskItemModel); //clear the views input fields and close it view.ClearFields(); view.CloseSelf(); } else { //transfer the use-cases error to the view view.ApplicationErrorMessage = output.Error; view.ApplicationError = true; } }