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; }
public JsonResult CreateResponsibilityTask(CreateUpdateResponsibilityTaskViewModel viewModel, DocumentsToSaveViewModel documentsToSave) { JsonResult result = Json(new { Success = false }); if (!ModelState.IsValid) { result = Json(new { Success = false, Errors = ModelState.GetErrorMessages() }); } else { try { var taskGuid = Guid.NewGuid(); SaveResponsibilityTaskResponse response = null; using (var session = _businessSafeSessionManager.Session) { // move this to Task base entity if(!viewModel.IsRecurring) { viewModel.TaskReoccurringTypeId = (int)TaskReoccurringType.None; } var request = SaveResponsibilityTaskRequest.Create( viewModel.CompanyId, viewModel.ResponsibilityId, viewModel.TaskId = viewModel.TaskId, viewModel.Title, viewModel.Description, viewModel.TaskReoccurringTypeId, viewModel.CompletionDueDate, viewModel.ReoccurringEndDate, CurrentUser.UserId, viewModel.AssignedToId.Value, (int) TaskStatus.Outstanding, viewModel.ReoccurringStartDate, !viewModel.DoNotSendTaskAssignedNotification, !viewModel.DoNotSendTaskCompletedNotification, !viewModel.DoNotSendTaskOverdueNotification, !viewModel.DoNotSendTaskDueTomorrowNotification, taskGuid, viewModel.ResponsibilityTaskSiteId.Value, documentsToSave.CreateDocumentRequests); response = _responsibilitiesService.SaveResponsibilityTask(request); _businessSafeSessionManager.CloseSession(); } _bus.Publish(new TaskAssigned {TaskGuid = taskGuid}); result = Json(new { Success = true, response.HasMultipleFrequencyChangeToTrue }); } catch (ValidationException validationException) { ModelState.AddValidationErrors(validationException); } } return result; }
public void when_create_task_viewmodel_should_call_correct_methods() { //given var target = GetTarget(); //when var viewModel = new CreateUpdateResponsibilityTaskViewModel { CompanyId = 1L, ResponsibilityId = 1L, TaskId = default(long), Title = "the title 12345", Description = "test description 12345", DoNotSendTaskCompletedNotification = true, DoNotSendTaskAssignedNotification = false, DoNotSendTaskOverdueNotification = true, DoNotSendTaskDueTomorrowNotification = true, AssignedTo = "User", AssignedToId = Guid.NewGuid(), IsRecurring = false, ReoccurringStartDate = null, ReoccurringEndDate = null, TaskReoccurringType = "3 Monthly", TaskReoccurringTypeId = 3, CompletionDueDate = null, ResponsibilityTaskSite = "Site", ResponsibilityTaskSiteId = 1L }; target.CreateResponsibilityTask(viewModel, new DocumentsToSaveViewModel()); //then _responsibilitiesService .Verify(x => x.SaveResponsibilityTask(It.IsAny<SaveResponsibilityTaskRequest>()), Times.Once()); }