Exemple #1
0
        public void AddPlantToGroup(string plantId, int plantGroupId)
        {
            Guid g = new Guid(plantId);

            var plantGroup = _dbContext.PlantsGroups.FirstOrDefault(x => x.Id == plantGroupId);
            var plant      = _dbContext.Plants.FirstOrDefault(x => x.Id == g);

            plantGroup.Plants.Add(plant);

            _dbContext.SaveChanges();
        }
        public void AddPlantsAction(User user, PlantsActionDto plantsActionDto)
        {
            if (plantsActionDto.Days != Days.NONE)
            {
                try
                {
                    var plant = _dbContext.Plants.FirstOrDefault(x =>
                                                                 x.Id == plantsActionDto.PlantId);

                    var rule = new Rule()
                    {
                        Days = plantsActionDto.Days,
                        WaterInMilliliters = plantsActionDto.AmountOfWaterMilliliters,
                    };

                    plant.Rule = rule;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            var action = new ScheduledAction
            {
                ImagePath = plantsActionDto.ImageUri,
                AmountOfWaterMilliliters = plantsActionDto.AmountOfWaterMilliliters,
                ScheduledDate            = plantsActionDto.ScheduledDate
            };

            action.PlantId = plantsActionDto.PlantId;

            user.PlantsAudits.Add(action);


            _dbContext.SaveChanges();

            var rules = _dbContext.Rules.ToString();
        }
Exemple #3
0
        public void CreateGroup(int userId, string name)
        {
            var user = _dbContext.Users.Include(x => x.PlantsGroups)
                       .FirstOrDefault(x => x.Id == userId);

            var plantGroup = new PlantsGroup()
            {
                Name = name
            };

            user.PlantsGroups.Add(plantGroup);
            _dbContext.Add(plantGroup);

            _dbContext.SaveChanges();
        }