public ActionResult Index() { var today = DateTime.UtcNow.Date; var expiredTasks = _taskRepository.GetAllBy(t => (t.TaskStatus != ProjectTaskStatus.Completed && t.TaskStatus != ProjectTaskStatus.Cancelled) && t.DueDate < today).ToList(); foreach (var expiredTask in expiredTasks) { var taskId = expiredTask.Id; var selectedTask = _taskRepository.Get(taskId); var dueDate = selectedTask.DueDate?.ToString("d") ?? "No due date"; var activity = new TaskActivity { TaskId = selectedTask.Id, Title = "Missed DueDate", Comment = $"Missed the due date of {dueDate} as of {DateTime.UtcNow:d}, Sent the reminder", CreatedByUserId = 1 }; _taskActivityRepository.Create(activity); _unitOfWork.Commit(); #if !DEBUG _emailComposerService.TaskMissed(taskId); #endif } return(Json(true, JsonRequestBehavior.AllowGet)); }
public ActionResult Create(CreateTaskViewModel vm) { if (ModelState.IsValid) { var newTask = new Task { Title = vm.Title, Description = vm.Description, ExpectedTime = vm.ExpectedTime, ActualTime = vm.ActualTime, TaskStatus = vm.TaskStatus, Priority = vm.Priority, AssigneeId = vm.AssigneeId, StartDate = vm.StartDate, DueDate = vm.DueDate, ProjectId = vm.ProjectId, ParentId = vm.ParentId, CreatedByUserId = WebUser.Id }; _taskRepository.Create(newTask); _unitOfWork.Commit(); #if !DEBUG _emailComposerService.TaskCreated(newTask.Id); #endif var selectedTask = _taskRepository.Get(newTask.Id, "Assignee.User.Person"); // Log as a Task Activity var dueDate = selectedTask.DueDate?.ToString("d") ?? "No due date"; var assignedTo = selectedTask.AssigneeId.HasValue ? selectedTask.Assignee.User.Person.Name : "No Assignee"; var activity = new TaskActivity { TaskId = selectedTask.Id, Title = "Created", Comment = $"{WebUser.Name} created the Task at {selectedTask.CreatedOn.ToString("G")} with state {selectedTask.TaskStatus}, expected hours {selectedTask.ExpectedTime}, due date as {dueDate} and assigned to {assignedTo}", CreatedByUserId = WebUser.Id }; _taskActivityRepository.Create(activity); _unitOfWork.Commit(); // Update Task Code if (selectedTask != null) { selectedTask.Code = $"TK{newTask.Id}"; _taskRepository.Update(selectedTask); _unitOfWork.Commit(); var assignedToUser = _userRepository.Get(selectedTask.AssigneeId.GetValueOrDefault()); if (assignedToUser != null) { _notificationService.NotifyUser("New Task", selectedTask.Title, assignedToUser.Code); } } return(RedirectToAction("Index")); } var myProjects = GetAllProjectsForMe(); var userList = GetAllMyReportees(); ViewBag.AssigneeId = new SelectList(userList, "Id", "Person.Name", vm.AssigneeId); ViewBag.ProjectId = new SelectList(myProjects, "Id", "Title", vm.ProjectId); return(View(vm)); }
public ActionResult Update(Task vm) { ApiResult <Task> apiResult; if (ModelState.IsValid) { if (vm.Id > 0) { apiResult = TryExecute(() => { var selectedTask = _taskRepository.Get(vm.Id, "Assignee.User.Person"); if (selectedTask != null) { selectedTask.ProjectId = vm.ProjectId; selectedTask.Title = vm.Title; selectedTask.Description = vm.Description; selectedTask.ExpectedTime = vm.ExpectedTime; selectedTask.TaskStatus = vm.TaskStatus; selectedTask.Priority = vm.Priority; selectedTask.AssigneeId = vm.AssigneeId; selectedTask.StartDate = vm.StartDate; selectedTask.DueDate = vm.DueDate; selectedTask.TaskBilling = vm.TaskBilling; selectedTask.UpdatedByUserId = WebUser.Id; _taskRepository.Update(selectedTask); _unitOfWork.Commit(); // Log as a Task Activity var dueDate = selectedTask.DueDate?.ToString("d") ?? "No due date"; var assignedTo = selectedTask.AssigneeId.HasValue ? selectedTask.Assignee.User.Person.Name : "No Assignee"; var activity = new TaskActivity { TaskId = selectedTask.Id, Title = "Updated", Comment = $"{WebUser.Name} updated the Task at {DateTime.UtcNow.ToString("G")} with state {selectedTask.TaskStatus}, expected hours {selectedTask.ExpectedTime}, due date as {dueDate} and assigned to {assignedTo}", CreatedByUserId = WebUser.Id }; _taskActivityRepository.Create(activity); _unitOfWork.Commit(); #if !DEBUG _emailComposerService.TaskUpdated(selectedTask.Id); #endif } return(selectedTask); }, "Task updated sucessfully"); } else { apiResult = TryExecute(() => { var newTask = new Task { Title = vm.Title, Description = vm.Description, ExpectedTime = vm.ExpectedTime, ActualTime = vm.ActualTime, TaskStatus = vm.TaskStatus, Priority = vm.Priority, AssigneeId = vm.AssigneeId, StartDate = vm.StartDate, DueDate = vm.DueDate, ProjectId = vm.ProjectId, ParentId = vm.ParentId, CreatedByUserId = WebUser.Id, TaskBilling = vm.TaskBilling }; _taskRepository.Create(newTask); _unitOfWork.Commit(); var selectedTask = _taskRepository.Get(newTask.Id, "Assignee.User.Person"); // Log as a Task Activity var dueDate = selectedTask.DueDate?.ToString("d") ?? "No due date"; var assignedTo = selectedTask.AssigneeId.HasValue ? selectedTask.Assignee.User.Person.Name : "No Assignee"; var activity = new TaskActivity { TaskId = selectedTask.Id, Title = "Created", Comment = $"{WebUser.Name} created the Task at {selectedTask.CreatedOn.ToString("G")} with state {selectedTask.TaskStatus}, expected hours {selectedTask.ExpectedTime}, due date as {dueDate} and assigned to {assignedTo}", CreatedByUserId = WebUser.Id }; _taskActivityRepository.Create(activity); _unitOfWork.Commit(); // Update Task Code if (selectedTask != null) { selectedTask.Code = $"TK{newTask.Id}"; _taskRepository.Update(selectedTask); _unitOfWork.Commit(); } #if !DEBUG _emailComposerService.TaskCreated(newTask.Id); #endif return(vm); }, "Task created sucessfully"); } } else { apiResult = ApiResultFromModelErrors <Task>(); } return(Json(apiResult, JsonRequestBehavior.AllowGet)); }