Exemplo n.º 1
0
        public bool IsValid <T>(T model, Action <bool> curAction, bool creating)
        {
            var results = new List <ValidationResult>();
            var context = new ValidationContext(model);

            bool isValid = Validator.TryValidateObject(model, context, results, true);

            if (!isValid)
            {
                Console.WriteLine();
                foreach (var error in results)
                {
                    Console.WriteLine(error.ErrorMessage);
                }
                inAppBehavior.ContinueOrQuit(curAction, inAppBehavior.Menu, creating);
            }

            return(isValid);
        }
Exemplo n.º 2
0
        private void OrderByOrQuit(bool asc)
        {
            Console.Write("Choose option: ");
            int lastPropIndex = propIndex;

            int.TryParse(Console.ReadLine().Trim(), out propIndex);

            if (propIndex < 1 || propIndex > optionsLength + 2)
            {
                Console.WriteLine("You entered wrong value");
                inAppBehavior.ContinueOrQuit(OrderByOrQuit, inAppBehavior.Menu);
                return;
            }

            if (propIndex == optionsLength + 2)
            {
                inAppBehavior.Menu();
                return;
            }

            if (propIndex == optionsLength + 1)
            {
                searcher.Search();
                action(orderBy, lastPropIndex);
                return;
            }

            asc     = lastPropIndex == propIndex ? !asc : true;
            orderBy = properties[propIndex - 1].Name;
            if (!asc)
            {
                orderBy += " desc";
            }

            action(orderBy, propIndex);
        }