public static CreateUpdateResponsibilityTaskViewModel CreateFrom(long companyId, ResponsibilityDto responsibility, TaskDto task) { var model = new CreateUpdateResponsibilityTaskViewModel(); model.CompanyId = companyId; model.ResponsibilityId = responsibility.Id; model.ResponsibilitySiteId = responsibility.Site != null ? responsibility.Site.Id : 0; model.ResponsibilitySite = responsibility.Site != null ? responsibility.Site.Name : string.Empty; model.TaskId = task != null ? task.Id : default(long); model.TaskStatusId = task != null ? task.TaskStatusId : default(int); model.Title = task != null ? task.Title : string.Empty; model.Description = task != null ? task.Description : string.Empty; model.IsRecurring = task != null && task.IsReoccurring; model.TaskReoccurringTypeId = task != null ? (int) task.TaskReoccurringType : default(int); model.TaskReoccurringType = task != null ? task.TaskReoccurringType.ToString() : string.Empty; model.CompletionDueDate = task != null ? task.TaskCompletionDueDate : string.Empty; model.ReoccurringStartDate = task != null ? task.TaskCompletionDueDate : string.Empty; model.ReoccurringEndDate = task != null ? task.TaskReoccurringEndDate : null; model.DoNotSendTaskAssignedNotification = task != null && !task.SendTaskCompletedNotification; model.DoNotSendTaskCompletedNotification = task != null && !task.SendTaskCompletedNotification; model.DoNotSendTaskOverdueNotification = task != null && !task.SendTaskOverdueNotification; model.DoNotSendTaskDueTomorrowNotification = task != null && !task.SendTaskDueTomorrowNotification; model.ResponsibilityTaskSiteId = task != null && task.Site != null ? task.Site.Id : default(long); model.ResponsibilityTaskSite = task != null && task.Site != null ? task.Site.Name : string.Empty; model.AssignedTo = task != null && task.TaskAssignedTo != null ? task.TaskAssignedTo.FullName : string.Empty; model.AssignedToId = task != null && task.TaskAssignedTo != null ? task.TaskAssignedTo.Id : new Guid(); return model; }
private static HazardousSubstanceRiskAssessmentFurtherControlMeasureViewModel CreateFrom(TaskDto furtherControlMeasureTask) { return new HazardousSubstanceRiskAssessmentFurtherControlMeasureViewModel() { Id = furtherControlMeasureTask.Id, ActionTitle = furtherControlMeasureTask.Title, ActionDescription = furtherControlMeasureTask.Description, AssignedTo = furtherControlMeasureTask.TaskAssignedTo != null ? furtherControlMeasureTask.TaskAssignedTo.FullName : string.Empty, TaskCompletionDueDate = furtherControlMeasureTask.TaskCompletionDueDate, TaskStatus = EnumHelper.GetEnumDescription(furtherControlMeasureTask.DerivedDisplayStatus), TaskReoccurringType = furtherControlMeasureTask.TaskReoccurringType, TaskReoccurringEndDate = furtherControlMeasureTask.TaskReoccurringEndDate, CreatedOn = furtherControlMeasureTask.CreatedDate, TaskGuid = furtherControlMeasureTask.TaskGuid }; }
private static TaskViewModel CreateFrom(TaskDto task) { var taskViewModel = new TaskViewModel { Id = task.Id, Reference = task.Reference, Title = task.Title, Description = task.Description, TaskAssignedTo = task.TaskAssignedTo.FullName, TaskCategory = task.TaskCategory.Category, IsDeleted = task.Deleted, IsReoccurring = task.IsReoccurring, TaskStatus = task.TaskStatusString.AddSpacesToName(), DerivedDisplayStatus = EnumHelper.GetEnumDescription(task.DerivedDisplayStatus), TaskReoccurringType = task.TaskReoccurringType, TaskReoccurringEndDate = task.TaskReoccurringEndDate, CreatedDate = task.CreatedDate, TaskCompletionDueDate = task.TaskCompletionDueDate, HasDocuments = task.Documents.Any(), HasCompletedDocuments = task.Documents.Any(d => d.DocumentOriginType == DocumentOriginType.TaskCompleted), TaskType = task.GetType().Name, TaskGuid = task.TaskGuid, CompletedBy = task.TaskCompletedBy != null ? task.TaskCompletedBy.FullName : string.Empty, CompletedOn = task.TaskCompletedDate.HasValue ? task.TaskCompletedDate.Value.ToLocalShortDateString() : string.Empty }; if (taskViewModel.IsReviewTask()) { var riskAssessmentReviewTaskDto = task as RiskAssessmentReviewTaskDto; taskViewModel.RiskAssessmentId = riskAssessmentReviewTaskDto != null && riskAssessmentReviewTaskDto.RiskAssessment != null ? riskAssessmentReviewTaskDto.RiskAssessment.Id : default(long); taskViewModel.Title = riskAssessmentReviewTaskDto.RiskAssessment.Title; taskViewModel.Reference = riskAssessmentReviewTaskDto.RiskAssessment.Reference; } return taskViewModel; }
protected TaskDto PopulateTaskDto(Task entity, TaskDto dto) { dto.Id = entity.Id; dto.Title = entity.Title; dto.Description = entity.Description; dto.Reference = entity.Reference; dto.TaskGuid = entity.TaskGuid; //todo: change task assignedto to employeeDto dto.TaskAssignedTo = entity.TaskAssignedTo != null ? new EmployeeDtoMapper().Map(entity.TaskAssignedTo) //Replaced:TaskAssignedToDto.CreateFrom(entity.TaskAssignedTo) : null; //todo: TaskCompletionDueDate should be DateTime? dto.TaskCompletionDueDate = entity.TaskCompletionDueDate.HasValue ? entity.TaskCompletionDueDate.Value.ToShortDateString() : null; dto.TaskStatus = entity.TaskStatus; dto.TaskStatusString = entity.TaskStatus.ToString(); dto.TaskStatusId = (int) entity.TaskStatus; dto.TaskCompletedComments = entity.TaskCompletedComments; dto.TaskCompletedDate = entity.TaskCompletedDate; //todo: should be ResponsibilityTaskCategoryDto and should be called category. dto.TaskCategory = TaskCategoryDtoMapper.Map(entity.Category); dto.Documents = entity.Documents != null ? new TaskDocumentDtoMapper().Map(entity.Documents) : null; dto.IsReoccurring = entity.TaskReoccurringType != TaskReoccurringType.None; //TODO: This does not belong here, it belongs in the entity then map that. PTD. dto.TaskReoccurringType = entity.TaskReoccurringType; dto.TaskReoccurringEndDate = entity.TaskReoccurringEndDate; dto.Deleted = entity.Deleted; //todo: rename and make correct type dto.CreatedDate = entity.CreatedOn.HasValue ? entity.CreatedOn.Value.ToShortDateString() : ""; dto.RiskAssessment = entity.RiskAssessment != null ? new RiskAssessmentDtoMapper().MapWithTitleReference(entity.RiskAssessment) : null; dto.SendTaskNotification = entity.SendTaskNotification.GetValueOrDefault(); dto.SendTaskCompletedNotification = entity.SendTaskCompletedNotification.GetValueOrDefault(); dto.SendTaskOverdueNotification = entity.SendTaskOverdueNotification.GetValueOrDefault(); dto.SendTaskDueTomorrowNotification = entity.SendTaskDueTomorrowNotification.GetValueOrDefault(); if (entity.TaskCompletedDate.HasValue && entity.LastModifiedBy != null && entity.LastModifiedBy.Employee != null) { dto.TaskCompletedBy = new UserEmployeeDto() { EmployeeId = entity.LastModifiedBy.Employee.Id , Forename = entity.LastModifiedBy.Employee.Forename , Surname = entity.LastModifiedBy.Employee.Surname }; } dto.Site = entity.Site != null ? new SiteStructureElementDtoMapper().Map(entity.Site) : null; dto.DerivedDisplayStatus = entity.DerivedDisplayStatus; return dto; }
public TaskMapperFactory(Task entity) { _entity = entity; dto = new TaskDto(); if (entity.Self as ResponsibilityTask != null) { dto = new ResponsibilityTaskDto(); } if (entity.Self as RiskAssessmentReviewTask != null) { dto = new RiskAssessmentReviewTaskDto(); } if (entity.Self as MultiHazardRiskAssessmentFurtherControlMeasureTask != null) { if (entity.RiskAssessment.Self is GeneralRiskAssessment) { dto = new MultiHazardRiskAssessmentFurtherControlMeasureTaskDto(); dto.DefaultDocumentType = DocumentTypeEnum.GRADocumentType; //TODO: This does not belong here, it belongs in the entity then map that. PTD. } if (entity.RiskAssessment.Self is PersonalRiskAssessment) { dto = new MultiHazardRiskAssessmentFurtherControlMeasureTaskDto(); dto.DefaultDocumentType = DocumentTypeEnum.PRADocumentType; //TODO: This does not belong here, it belongs in the entity then map that. PTD. } } if (entity.Self as HazardousSubstanceRiskAssessmentFurtherControlMeasureTask != null) { dto = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTaskDto(); dto.DefaultDocumentType = DocumentTypeEnum.HSRADocumentType; //TODO: This does not belong here, it belongs in the entity then map that. PTD. } if (entity.Self as FireRiskAssessmentFurtherControlMeasureTask != null) { dto = new FireRiskAssessmentFurtherControlMeasureTaskDto(); dto.DefaultDocumentType = DocumentTypeEnum.FRADocumentType; //TODO: This does not belong here, it belongs in the entity then map that. PTD. } dto.Id = entity.Id; dto.Title = entity.Title; dto.Description = entity.Description; dto.Reference = entity.Reference; dto.TaskGuid = entity.TaskGuid; //todo: change task assignedto to employeeDto dto.TaskAssignedTo = entity.TaskAssignedTo != null ? new EmployeeDtoMapper().Map(entity.TaskAssignedTo) //Replaced:TaskAssignedToDto.CreateFrom(entity.TaskAssignedTo) : null; //todo: TaskCompletionDueDate should be DateTime? dto.TaskCompletionDueDate = entity.TaskCompletionDueDate.HasValue ? entity.TaskCompletionDueDate.Value.ToShortDateString() : null; dto.TaskStatus = entity.TaskStatus; dto.TaskStatusString = entity.TaskStatus.ToString(); dto.TaskStatusId = (int)entity.TaskStatus; dto.TaskCompletedComments = entity.TaskCompletedComments; dto.TaskCompletedDate = entity.TaskCompletedDate; //todo: should be ResponsibilityTaskCategoryDto and should be called category. dto.TaskCategory = TaskCategoryDtoMapper.Map(entity.Category); dto.Documents = entity.Documents != null ? new TaskDocumentDtoMapper().Map(entity.Documents) : null; dto.IsReoccurring = entity.TaskReoccurringType != TaskReoccurringType.None; //TODO: This does not belong here, it belongs in the entity then map that. PTD. dto.TaskReoccurringType = entity.TaskReoccurringType; dto.TaskReoccurringEndDate = entity.TaskReoccurringEndDate; dto.Deleted = entity.Deleted; //todo: rename and make correct type dto.CreatedDate = entity.CreatedOn.HasValue ? entity.CreatedOn.Value.ToShortDateString() : ""; dto.RiskAssessment = entity.RiskAssessment != null ? new RiskAssessmentDtoMapper().MapWithEmployeesAndNonEmployeesAndSiteAndRiskAssessor(entity.RiskAssessment) : null; dto.SendTaskNotification = entity.SendTaskNotification.GetValueOrDefault(); dto.SendTaskCompletedNotification = entity.SendTaskCompletedNotification.GetValueOrDefault(); dto.SendTaskOverdueNotification = entity.SendTaskOverdueNotification.GetValueOrDefault(); dto.SendTaskDueTomorrowNotification = entity.SendTaskDueTomorrowNotification.GetValueOrDefault(); if (entity.TaskCompletedDate.HasValue && entity.LastModifiedBy != null && entity.LastModifiedBy.Employee != null) { dto.TaskCompletedBy = new UserEmployeeDto() { EmployeeId = entity.LastModifiedBy.Employee.Id , Forename = entity.LastModifiedBy.Employee.Forename , Surname = entity.LastModifiedBy.Employee.Surname }; } dto.Site = entity.Site != null ? new SiteStructureElementDtoMapper().Map(entity.Site) : null; dto.DerivedDisplayStatus = entity.DerivedDisplayStatus; }
public void When_GetRiskAssessmentArea_Then_should_return_correct_result(string taskCategory, string expectedArea) { // Arrange var taskDtos = new List<TaskDto>(); var newTaskDto = new TaskDto() { Id = 123, Reference = "Reference", Title = "Title", Description = "Description", TaskAssignedTo = new EmployeeDto(), TaskCategory = new TaskCategoryDto() { Id = 123L, Category = taskCategory }, Deleted = true, IsReoccurring = true, TaskStatusString = "Deleted", TaskReoccurringType = TaskReoccurringType.Weekly, TaskReoccurringEndDate = DateTime.Now, CreatedDate = "23/06/1980", TaskCompletionDueDate = "23/06/2012", Documents = new List<TaskDocumentDto>() }; taskDtos.Add(newTaskDto); var viewModel = TaskViewModel.CreateFrom(taskDtos).First(); // Act var result = viewModel.GetRiskAssessmentArea(); // Assert Assert.That(result, Is.EquivalentTo(expectedArea)); }
public void Given_a_task_dto_When_Create_From_is_requested_Then_all_fields_is_mapped() { // Arrange var taskDtos = new List<TaskDto>(); var newTaskDto = new TaskDto() { Id = 123, Reference = "Reference", Title = "Title", Description = "Description", TaskAssignedTo = new EmployeeDto(), TaskCategory = new TaskCategoryDto() { Id = 123L, Category = "TestCategory" }, Deleted = true, IsReoccurring = true, TaskStatusString = "Deleted", TaskReoccurringType = TaskReoccurringType.Weekly, TaskReoccurringEndDate = DateTime.Now, CreatedDate = "23/06/1980", TaskCompletionDueDate = "23/06/2012", Documents = new List<TaskDocumentDto>(), TaskCompletedBy = new UserEmployeeDto() { Forename = "Paul", Surname = "McGrath"}, TaskCompletedDate = new DateTimeOffset(DateTime.Now), DerivedDisplayStatus = DerivedTaskStatusForDisplay.NoLongerRequired }; taskDtos.Add(newTaskDto); // Act var result = TaskViewModel.CreateFrom(taskDtos).ToList(); // Assert Assert.That(result.ElementAt(0), Is.Not.Null); Assert.That(result.ElementAt(0).Id, Is.EqualTo(newTaskDto.Id)); Assert.That(result.ElementAt(0).Reference, Is.EqualTo(newTaskDto.Reference)); Assert.That(result.ElementAt(0).Title, Is.EqualTo(newTaskDto.Title)); Assert.That(result.ElementAt(0).Description, Is.EqualTo(newTaskDto.Description)); Assert.That(result.ElementAt(0).TaskAssignedTo, Is.EqualTo(newTaskDto.TaskAssignedTo.FullName)); Assert.That(result.ElementAt(0).IsDeleted, Is.EqualTo(newTaskDto.Deleted)); Assert.That(result.ElementAt(0).IsReoccurring, Is.EqualTo(newTaskDto.IsReoccurring)); Assert.That(result.ElementAt(0).TaskStatus, Is.EqualTo(newTaskDto.TaskStatusString)); Assert.That(result.ElementAt(0).TaskReoccurringType, Is.EqualTo(newTaskDto.TaskReoccurringType)); Assert.That(result.ElementAt(0).TaskReoccurringEndDate, Is.EqualTo(newTaskDto.TaskReoccurringEndDate)); Assert.That(result.ElementAt(0).CreatedDate, Is.EqualTo(newTaskDto.CreatedDate)); Assert.That(result.ElementAt(0).TaskCompletionDueDate, Is.EqualTo(newTaskDto.TaskCompletionDueDate)); Assert.That(result.ElementAt(0).CompletedBy, Is.EqualTo(newTaskDto.TaskCompletedBy.FullName)); Assert.That(result.ElementAt(0).CompletedOn, Is.EqualTo(newTaskDto.TaskCompletedDate.Value.ToLocalShortDateString())); Assert.That(result.ElementAt(0).DerivedDisplayStatus, Is.EqualTo(EnumHelper.GetEnumDescription(DerivedTaskStatusForDisplay.NoLongerRequired))); Assert.IsFalse(result.ElementAt(0).HasDocuments); Assert.IsFalse(result.ElementAt(0).HasCompletedDocuments); }