Exemplo n.º 1
0
        public static bool NewTableItemIsValid(AsSession session, AsSessionAnimalSample item)
        {
            if (!item.idfMaterial.HasValue &&
                session.ASAnimalsSamples.Any(i => i != item && i.idfFarm == item.idfFarm && i.idfAnimal == item.idfAnimal && !i.idfMaterial.HasValue))
            {
                throw new ValidationModelException("AsSession.DetailsTableView.DuplicateAnimalWithoutSample", "idfAnimal", "idfAnimal", new string[] { "Error" }, typeof(PredicateValidator), ValidationEventType.Error, session);
            }

            if (session.Diseases.Count(x => (x.idfsSpeciesType == item.idfsSpeciesType || !x.idfsSpeciesType.HasValue) && !x.IsMarkedToDelete) == 0 &&
                session.Diseases.Count(x => !x.IsMarkedToDelete) > 0 &&
                item.idfsSpeciesType != 0)
            {
                throw new ValidationModelException("AsSession.DetailsTableView.SpeciesIsNotInTheList", "idfAnimal", "idfAnimal", new string[] { "Error" }, typeof(PredicateValidator), ValidationEventType.Error, session);
            }

            if (session.ASAnimalsSamples.Count(x => !Utils.IsEmpty(x.strFieldBarcode) && !Utils.IsEmpty(item.strFieldBarcode) &&
                                               x.idfsSampleType == item.idfsSampleType &&
                                               x.idfAnimal == item.idfAnimal &&
                                               x.strFieldBarcode.Equals(item.strFieldBarcode, StringComparison.InvariantCultureIgnoreCase)) > 1)
            {
                throw new ValidationModelException("AsSession.DetailsTableView.DuplicateSample", "idfAnimal", "idfAnimal", new string[] { "Error" }, typeof(PredicateValidator), ValidationEventType.Error, session);
            }

            session.OnPropertyChanged("DetailsTableView.Count");
            return(true);
        }
Exemplo n.º 2
0
        private static bool ASSamplesIsValid(AsSession session, AsSessionAnimalSample item)
        {
            if (item.datFieldCollectionDate.HasValue)
            {
                if (session.datStartDate.HasValue && item.datFieldCollectionDate < session.datStartDate)
                {
                    throw new ValidationModelException("AsSession.SummaryItem.datCollectionDate_msgId", "datCollectionDate", "datCollectionDate", new object[] { item.datFieldCollectionDate, session.datStartDate, session.datEndDate }, typeof(PredicateValidator), ValidationEventType.Error, session);
                }
                if (session.datEndDate.HasValue && item.datFieldCollectionDate > session.datEndDate)
                {
                    throw new ValidationModelException("AsSession.SummaryItem.datCollectionDate_msgId", "datCollectionDate", "datCollectionDate", new object[] { item.datFieldCollectionDate, session.datStartDate, session.datEndDate }, typeof(PredicateValidator), ValidationEventType.Error, session);
                }
            }

            session.OnPropertyChanged(_str_ASAnimalsSamples);
            return(true);
        }