Exemple #1
0
        public int DoSaveSample(Sample sample, Identification identification)
        {
            logger.Log(LogLevel.Trace, AppLib.GetCaller(logger));

            //Validate Order Object
            if (!sample.ValidateModel())
                throw new FaultException<ServiceFault>(new ServiceFault(sample.CurrentErrors), new FaultReason(SysVars.InvalidFormat));

            // Validate All SampleTests
            Dictionary<string, List<string>> sampleTestErrors = new Dictionary<string, List<string>>();
            foreach (SampleTest sampleTest in sample.SampleTests)
            {
                if (!sampleTest.ValidateModel())
                    sampleTestErrors = sampleTest.CurrentErrors;
            }
            if (sampleTestErrors.Count > 0)
                throw new FaultException<ServiceFault>(new ServiceFault(sampleTestErrors), new FaultReason(SysVars.InvalidFormat));

            // Validate All SampleCharges
            Dictionary<string, List<string>> chargesErrors = new Dictionary<string, List<string>>();
            foreach (SampleCharge charge in sample.SampleCharges)
            {
                if (!charge.ValidateModel())
                    chargesErrors = charge.CurrentErrors;
            }
            if (chargesErrors.Count > 0)
                throw new FaultException<ServiceFault>(new ServiceFault(chargesErrors), new FaultReason(SysVars.InvalidFormat));

            // Validate All SampleNotes
            Dictionary<string, List<string>> notesErrors = new Dictionary<string, List<string>>();
            foreach (SampleNote note in sample.SampleNotes)
            {
                if (!note.ValidateModel())
                    notesErrors = note.CurrentErrors;
            }
            if (notesErrors.Count > 0)
                throw new FaultException<ServiceFault>(new ServiceFault(notesErrors), new FaultReason(SysVars.InvalidFormat));

            // Save Order
            using (SampleDAO dao = new SampleDAO())
            {
                return dao.SaveSample(sample, identification);
            }
        }