public void AddNewTask(DataAccess.Task task) { var taskWithSameName = taskRepo.GetTaskByName(task.TaskName); if (taskWithSameName != null && taskWithSameName.TaskId > 0) { var customEx = new CustomValidationException(); customEx.AddException("TaskName", "Active task with same name is already present in the system"); throw customEx; } else { taskRepo.AddTask(task); } }
public void EditTask(DataAccess.Task task) { var taskWithSameName = taskRepo.GetTaskByName(task.TaskName); if (taskWithSameName != null && taskWithSameName.TaskId > 0 && taskWithSameName.TaskId != task.TaskId) { var customEx = new CustomValidationException(); customEx.AddException("TaskName", "Other active task with same name is already present in the system"); throw customEx; } else { bool isStartDateValidationPass = true; bool isEndDateValidationPass = true; var childTasks = GetChildTasks(task); if (childTasks.Count > 0) { isStartDateValidationPass = IsEditedParentStartDateValid(childTasks, task); isEndDateValidationPass = IsEditedParentEndDateValid(childTasks, task); } if (childTasks.Count == 0 || (isStartDateValidationPass && isEndDateValidationPass)) { taskRepo.EditTask(task); } else { var customEx = new CustomValidationException(); if (!isStartDateValidationPass) { customEx.AddException("StartDate", "One or more child task/tasks has/have earlier start date"); } if (!isEndDateValidationPass) { customEx.AddException("EndDate", "One or more child task/tasks has/have greater end date"); } throw customEx; } } }