public Result AssignSalesperson(CustomerFormDTO dto) { // Check if there are any available personnel if (!_salesRepo.GetAllAvailableSalespersons(_salesRepo.LoadSalespersons()).Any()) { // None available, return "All salespeople are busy. Please wait" return(new Result() { Success = false, ErrorMessage = "All salespeople are busy. Please wait." }); } else if (dto.Groups.Count == 0) { // No groups so pick one at random var availablePerson = _salesRepo.LoadSalespersons(); return(new Result() { Success = true, AssignedSalesPerson = ChooseRandom(availablePerson) }); } else { // pass groups into function to find best salesperson return(AllocateSalesperson(dto.Groups)); } }
public void UpdateAvailability(Salesperson person, bool isAvailable) { var salespersonList = _salesRepo.LoadSalespersons(); // Presume we always find the sales person here, for now the list is static so I am // not implementing error handling here. If this were to be extended I would add an // if to check that whether the list contains the person. salespersonList.Find(p => p.Name == person.Name).IsAvailable = isAvailable; using (StreamWriter file = File.CreateText(_dbPath)) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, salespersonList); } }