/// <summary> /// Validate Treatment machine to make sure all required information is present /// A treatment machine needs to have a unique name AND a capability /// </summary> /// <param name="machine"></param> /// <returns>true = treatment machine information is valid; false = treatment machine information is invalid</returns> public bool TreatmentMachineValidation(TreatmentMachine machine) { // treatment machine information can not be null if (machine == null) { return(false); } // treatment machine must have a name. if (string.IsNullOrEmpty(machine.MachineName)) { return(false); } // treamtent machine must have a unique name. if (PatientSchedulerContext.TreatmentMachines != null) { return (PatientSchedulerContext.TreatmentMachines.All( treatmentMachine => CultureInfo.CurrentCulture.CompareInfo.Compare(treatmentMachine.MachineName, machine.MachineName, CompareOptions.IgnoreCase) != 0)); } // treatment machine must have a capablity if (string.IsNullOrEmpty(machine.MachineCapability)) { return(false); } return(true); }
private void ImportMachines(JsonDataFileImporterReader importer) { var machines = importer.Machines(_filePath); foreach (var machine in machines) { var m = new TreatmentMachine { Name = machine.Name, CapabilityId = Data.Enumeration.FromName <TreatmentMachineCapability>(machine.Capability).Value, }; _context.Add(m); } _context.SaveChanges(); }
public Task <bool> Handle(RegisterAdvancedTreatmentMachineCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return(Task.FromResult(false)); } var treatmentMachine = new TreatmentMachine(Guid.NewGuid(), request.Name, TreatmentMachineType.Advanced); _treatmentMachineRepository.Add(treatmentMachine); if (Commit()) { _mediator.RaiseEvent(new TreatmentMachineAdvancedRegisteredEvent(treatmentMachine.Id, treatmentMachine.Name)); } return(Task.FromResult(true)); }