Exemplo n.º 1
0
        /// <summary>
        /// Attempts to add an antibiotic to the database
        /// </summary>
        /// <param name="name"></param>
        /// <param name="acceptableUses"></param>
        /// <param name="price"></param>
        /// <param name="toxicity"></param>
        /// <returns>
        /// True if it was added
        /// False otherwise
        /// </returns>
        public static bool addAntibiotic(String name, String acceptableUses, int price, String toxicity)
        {
            Antibiotic antibiotic = new Antibiotic();

            antibiotic.name           = name;
            antibiotic.acceptableUses = acceptableUses;
            antibiotic.price          = price;
            antibiotic.toxicity       = toxicity;
            return(Database.addAntibiotic(antibiotic));
        }
        /// <summary>
        /// Adds the antibiotic.
        /// </summary>
        /// <returns>The antibiotic.</returns>
        /// <param name="antibiotic">Antibiotic.</param>
        public static bool addAntibiotic(Antibiotic antibiotic)
        {
            var table = db.Table <Antibiotic>();

            foreach (var element in table)
            {
                if (element.name == antibiotic.name)
                {
                    return(false);
                }
            }
            db.Insert(antibiotic);
            return(true);
        }
        /// <summary>
        /// Gets the antibiotic.
        /// </summary>
        /// <returns>The antibiotic.</returns>
        /// <param name="name">Name.</param>
        public static Antibiotic getAntibiotic(String name)
        {
            Antibiotic antibiotic  = null;
            var        antibiotics = db.Table <Antibiotic>();

            foreach (var ab in antibiotics)
            {
                if (String.Compare(ab.name, name, true) == 0)
                {
                    antibiotic = ab;
                    break;
                }
            }
            return(antibiotic);
        }