// ---------------------------   Personal Plant    ----------------------------

        #region Personal Plant

        /// <summary>
        /// Adds a personal Plant to an account
        /// </summary>
        /// <param name="plantID">Plant ID</param>
        /// <param name="accID">Account ID</param>
        /// <param name="daysWater">Assigned days between waterings</param>
        /// <param name="nName">NickName</param>
        /// <returns>Returns the ID of the new Personal PLant</returns>
        public int AddPersonalPlant(int plantID, int accID, int daysWater, string nName)
        {
            int result = 0;

            using (plantdb = new LinQtoSQLDataContext(GetConnectionString()))
            {
                try
                {
                    plantdb.LoadOptions = SetDataLoadOptions(TableInUse.PersonalPlant);
                    PersonalPlant pplant = new PersonalPlant
                    {
                        pid         = plantID,
                        aid         = accID,
                        nname       = nName,
                        wduration   = daysWater,
                        lastwatered = DateTime.Today,
                        nextwatered = DateTime.Today.AddDays(daysWater)
                    };
                    plantdb.PersonalPlants.InsertOnSubmit(pplant);
                    plantdb.SubmitChanges();

                    result = pplant.id;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    result = 0;
                }
            }

            return(result);
        }
Exemple #2
0
        private Model.PersonalPlant ConvertPersonalPlant(PersonalPlant plant)
        {
            if (plant != null)
            {
                Model.PersonalPlant mPP = new Model.PersonalPlant
                {
                    Id          = plant.id,
                    PId         = plant.pid,
                    AId         = plant.aid,
                    NName       = plant.nname,
                    LastWatered = plant.lastwatered,
                    NextWatered = plant.nextwatered,
                    WDuration   = plant.wduration,

                    account = ConvertAccount(plant.Account),
                    plant   = ConvertPlant(plant.Plant)
                };

                return(mPP);
            }
            else
            {
                return(null);
            }
        }
        public bool UpdatePersonalPlant(int ppID, int daysWater, string nName)
        {
            bool result = false;

            using (plantdb = new LinQtoSQLDataContext(GetConnectionString()))
            {
                try
                {
                    plantdb.LoadOptions = SetDataLoadOptions(TableInUse.PersonalPlant);
                    PersonalPlant pp = plantdb.PersonalPlants.First(e => e.id.Equals(ppID));

                    pp.wduration = daysWater;
                    pp.nname     = nName;

                    plantdb.SubmitChanges();

                    result = true;
                }
                catch (Exception)
                {
                    result = false;
                }
            }

            return(result);
        }
        /// <summary>
        /// Find a single personal plant via PersonalPlant ID
        /// </summary>
        /// <param name="ppID">PersonalPlant ID</param>
        /// <returns>Returns the personal plant with the correct PersonalPlantID,
        ///  or it will return null if nothing is find.</returns>
        public PersonalPlant FindPersonalPlant(int ppID)
        {
            PersonalPlant result = null;

            using (plantdb = new LinQtoSQLDataContext(GetConnectionString()))
            {
                try
                {
                    plantdb.LoadOptions = SetDataLoadOptions(TableInUse.PersonalPlant);
                    PersonalPlant pp = plantdb.PersonalPlants.First(e => e.id.Equals(ppID));
                    result = new PersonalPlant
                    {
                        id          = pp.id,
                        aid         = pp.aid,
                        pid         = pp.pid,
                        nname       = pp.nname,
                        wduration   = pp.wduration,
                        lastwatered = pp.lastwatered,
                        nextwatered = pp.nextwatered,
                        Plant       = pp.Plant
                    };
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    result = null;
                }
            }

            return(result);
        }
        public bool UpdatePersonalPlantDates(int ppid)
        {
            using (plantdb = new LinQtoSQLDataContext(GetConnectionString()))
            {
                try
                {
                    plantdb.LoadOptions = SetDataLoadOptions(TableInUse.PersonalPlant);
                    PersonalPlant pp = plantdb.PersonalPlants.First(e => e.id.Equals(ppid));

                    pp.lastwatered = DateTime.Now;
                    pp.nextwatered = DateTime.Now.AddDays(pp.wduration);

                    plantdb.SubmitChanges();

                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
        /// <summary>
        /// Removes a PersonalPlant from the PersonalPlant Database
        /// </summary>
        /// <param name="ppID">The Personal Plant ID of the plant needed to be</param>
        /// <returns>Returns a boolean. True if successful, False if not.</returns>
        public bool RemovePersonalPlant(int ppID)
        {
            bool result = false;

            using (plantdb = new LinQtoSQLDataContext(GetConnectionString()))
            {
                try
                {
                    plantdb.LoadOptions = SetDataLoadOptions(TableInUse.PersonalPlant);
                    PersonalPlant pp = plantdb.PersonalPlants.First(e => e.id.Equals(ppID));

                    plantdb.PersonalPlants.DeleteOnSubmit(pp);
                    plantdb.SubmitChanges();
                    result = true;
                }
                catch (Exception)
                {
                    result = false;
                }
            }

            return(result);
        }
Exemple #7
0
 private void detach_PersonalPlants(PersonalPlant entity)
 {
     this.SendPropertyChanging();
     entity.Account = null;
 }
Exemple #8
0
 partial void DeletePersonalPlant(PersonalPlant instance);
Exemple #9
0
 partial void UpdatePersonalPlant(PersonalPlant instance);
Exemple #10
0
 partial void InsertPersonalPlant(PersonalPlant instance);
Exemple #11
0
 private void attach_PersonalPlants(PersonalPlant entity)
 {
     this.SendPropertyChanging();
     entity.Plant = this;
 }