Exemple #1
0
        /// <summary>
        /// Find a Plant by ID
        /// </summary>
        /// <param name="id">The id of the requested Plant</param>
        /// <returns>The <see cref="Plant"/></returns>
        public static Plant Find(int id)
        {
            const string selectPlantSql = "SELECT * FROM Plant WHERE id = ?";

            try
            {
                using (SQLiteConnection connection = Data.DataBaseAccess.DbConnection)
                {
                    SQLiteCommand command = connection.CreateCommand(selectPlantSql, id);
                    Plant         plant   = command.ExecuteQuery <Plant>().SingleOrDefault();
                    Strain        strain  = Core.Strain.Find(plant.StrainId);

                    if (plant == null)
                    {
                        return(null);
                    }

                    TimeSpan span = DateTime.Now.Subtract(plant.DatePlanted);
                    plant.Week      = span.Days / 7;
                    plant.ImagePath = ImageHandler.GetMostRecentDefaultImage(plant.Id);
                    plant.Strain    = strain;

                    return(plant);
                }
            }
            catch (SQLiteException)
            {
                return(null);
            }
        }
Exemple #2
0
        public static Strain Find(int id)
        {
            const string selectStrainSql = "SELECT * FROM Strain where id = ?";

            using (SQLiteConnection connection = Data.DataBaseAccess.DbConnection)
            {
                SQLiteCommand command = connection.CreateCommand(selectStrainSql, id);
                Strain        strain  = command.ExecuteQuery <Strain>().SingleOrDefault();
                return(strain);
            }
        }