Beispiel #1
0
        public static void Main(string[] args)
        {
            //PatientCartsControl catalogControl = new PatientCartsControl();
            PatientCartsControl catalogControl = new PatientCartsControl(true);              //from file

            bool toContinue = false;

            do
            {
                PatientCart cart = PatientCartControl.CreateNew();
                catalogControl.AddCart(cart);

                if (cart != null)
                {
                    PatientCart updatedCart = PatientCartControl.ChangeMandatoryQuestions(cart);
                    PatientCartsControl.UpdateCart(cart.Id, updatedCart);
                }

                toContinue = false;
                System.Console.WriteLine();
                System.Console.WriteLine("To continue? Y/N");
                string input = System.Console.ReadLine();
                toContinue = input.ToLower().Substring(0, 1) == "y" ? true : false;
            } while (toContinue);

            var res = catalogControl.GetAllCarts();

            System.Console.ReadKey();
        }
        public static void UpdateCart(int id, PatientCart cart)
        {
            bool isSuccess = _catalogue.Update(id, cart);

            if (!isSuccess)
            {
                System.Console.WriteLine("The cart has not been updated.");
                // new Exeption();
            }
        }
        public void AddCart(PatientCart cart)
        {
            if (cart == null)
            {
                System.Console.WriteLine("Bad Request.");
                return;
            }

            var createdBook = _catalogue.Add(cart);               //Conflict in case Add is not successful
        }
        public static PatientCart GetCart(int id)
        {
            PatientCart cart = _catalogue.Get(id);

            if (cart == null)
            {
                System.Console.WriteLine("Not found.");
            }
            return(cart);
        }
        public static PatientCart CreateNew()
        {
            System.Console.WriteLine();
            System.Console.WriteLine("Please write your name");
            string name = System.Console.ReadLine();

            if (name == null && name.Length == 0)
            {
                return(null);
            }

            PatientCart cart = new PatientCart();

            cart.Name = name;

            return(cart);
        }
        public static PatientCart ChangeMandatoryQuestions(PatientCart cart)
        {
            //AskMandatoryQuestions
            //=====================
            System.Console.WriteLine();
            System.Console.WriteLine("Mandatory questions:");
            System.Console.WriteLine("====================");

            System.Console.WriteLine();
            System.Console.WriteLine("Do you smoke or use snuff? (Y/N)");
            string answer1 = System.Console.ReadLine();

            System.Console.WriteLine();
            System.Console.WriteLine("Do you have any allergy? ");
            string answer2 = System.Console.ReadLine();

            System.Console.WriteLine();
            System.Console.WriteLine("How often do you eat sweets (candies, ice cream etc.)? Times per week.");
            string answer3 = System.Console.ReadLine();

            System.Console.WriteLine("........................................................................");

            //update the cart
            //===============

            //DoSmokeSnuff
            cart.DoSmokeSnuff = answer1.ToLower().Substring(0, 1) == "y" ? true : false;

            //HasAnyAllergy
            cart.HasAnyAllergy = answer2.ToLower().Substring(0, 1) == "n" ? null : answer2;

            //HasAnyAllergy
            int  number;
            bool isParseSuccessful = int.TryParse(answer3, out number);

            if (isParseSuccessful)
            {
                cart.EatsSugarTimesId = number;
            }

            return(cart);
        }