public void StaffManagementController_AssignTask() { var mockRepo = new Mock <IRepository>(); var detail = new AssignedtaskViewModel { TaskID = 1, StaffID = 1, AsiggnedHours = 4, AssignedDate = DateTime.Now }; mockRepo.Setup(repo => repo.AssignedTask(detail)).Returns("Added"); var controller = new StaffManagementController(mockRepo.Object); var result = controller.AssignTask(detail) as OkResult; Assert.AreEqual(result.StatusCode, 200); }
public IActionResult AssignTask(AssignedtaskViewModel assignedTask) { if (assignedTask != null) { var res = _repo.AssignedTask(assignedTask); if (res == "Added") { return(Ok()); } else { return(Content(res)); } } else { return(BadRequest()); } }
public string AssignedTask(AssignedtaskViewModel assignedTask) { try { var staffid = _dbContext.StaffDetails.Where(x => x.ID == assignedTask.StaffID).FirstOrDefault(); if (staffid.IsAvailable != false) { var TaskIid = _dbContext.TaskDetails.Where(x => x.ID == assignedTask.TaskID).FirstOrDefault(); if (TaskIid.Hour >= assignedTask.AsiggnedHours) { AssignedTask astask = new AssignedTask { StaffID = staffid, TaskID = TaskIid, AsiggnedHours = assignedTask.AsiggnedHours, AssignedDate = assignedTask.AssignedDate }; var taskRemainingHour = (TaskIid.Hour - assignedTask.AsiggnedHours); _dbContext.AssignedTasks.Add(astask); _dbContext.TaskDetails.Where(x => x.ID == assignedTask.TaskID).ToList().ForEach(i => i.Hour = taskRemainingHour); _dbContext.StaffDetails.Where(x => x.ID == assignedTask.StaffID).ToList().ForEach(i => i.IsAvailable = false); _dbContext.SaveChanges(); return("Added"); } else { return("Please provide hours less than or equal to : " + TaskIid.Hour); } } else { return("Staff is Already working on some task."); } } catch (Exception ex) { return("Exception while assigning task" + ex.Source); } }