public void ValidateBiggerBox()
 {
     plantlist.Add(new Plant("sun", 5));
     plantlist.Add(new Plant("marigold", 10));
     myGardenBox = new MyPlants(8, 8);
     myGardenBox.AddPlantsToGardenBox(plantlist);
     Assert.AreEqual(myGardenBox.CalculatePlanting(1), 40);
     Assert.AreEqual(myGardenBox.CalculatePlanting(0), 20);
 }
        //DeleteMyPlant method takes in the myPlantID and deletes the plant that matches with that ID from MyPlant list.
        public bool DeleteMyPlant(int myPlantID)
        {
            MyPlants myPlants = ctx.MyPlants.Single(e => e.MyPlantID == myPlantID);

            if (myPlants.UserID != _userID)
            {
                return(false);
            }
            ctx.MyPlants.Remove(myPlants);
            return(ctx.SaveChanges() == 1);
        }
        //AddNote allows user to add a note to a plant on MyPlant list. It takes MyPlantID and adds note to plant that matches with MyPlantID.
        public bool AddNote(AddNotesToMyPlant model)
        {
            MyPlants myPlants = ctx.MyPlants.Single(e => e.MyPlantID == model.MyPlantID);

            if (myPlants.UserID != _userID)
            {
                return(false);
            }
            myPlants.Notes = model.Notes;
            return(ctx.SaveChanges() == 1);
        }
        //UpdateMyPlant method takes in myPlantID of the plant you would like to update and new infomation that needs to be updated.
        //Populates the new updated information using UpdateMyPlantModel
        public bool UpdateMyPlant(UpdateMyPlantModel model)
        {
            MyPlants myPlants = ctx.MyPlants.Single(e => e.MyPlantID == model.MyPlantID);

            if (myPlants.UserID != _userID)
            {
                return(false);
            }
            myPlants.Location     = model.Location;
            myPlants.DatePlanted  = model.DatePlanted;
            myPlants.Photo        = model.Photo;
            myPlants.Notes        = model.Notes;
            myPlants.Year         = model.Year;
            myPlants.ModifiedDate = DateTimeOffset.UtcNow;
            return(ctx.SaveChanges() == 1);
        }
        //AddMyPlantMethod allows posting new plant to my plant based of AddMyPlantModel
        public bool AddMyPlant(AddMyPlantModel model)
        {
            MyPlants myPlants = new MyPlants
            {
                UserID      = _userID,
                Location    = model.Location,
                PlantID     = model.PlantID,
                DatePlanted = model.DatePlanted,
                Photo       = model.Photo,
                Notes       = model.Notes,
                Year        = model.Year,
                CreatedDate = DateTimeOffset.UtcNow
            };

            ctx.MyPlants.Add(myPlants);
            return(ctx.SaveChanges() == 1);
        }
Beispiel #6
0
        public Object AddToMyPlants(MyPlants w)
        {
            IEnumerable <JoinedPlant> m = dal.GetMyPlants(w.UserID);
            int plantID = w.PlantID;
            int result  = 0;

            foreach (JoinedPlant plant in m)
            {
                if (plant.ID == (int)w.PlantID)
                {
                    return(new
                    {
                        result = result,
                        success = result == 1 ? true : false
                    });
                }
            }
            result = dal.AddToMyPlants(w);
            return(new
            {
                result = result,
                success = result == 1 ? true : false
            });
        }