Beispiel #1
0
        public void StopWatering(int tapMangoPlantId)
        {
            var now = DateTime.Now;

            var tapMangoPlant  = TapMangoPlant.GetById(tapMangoPlantId);
            var currentSession = tapMangoPlant.Sessions.First();

            if (currentSession == null)
            {
                throw new Exception("Can't stop when you are not watering plant!");
            }
            if (currentSession.StatusId == 2 || now > currentSession.ExpectToCompleteOn)
            {
                throw new Exception("Can't stop when you are not watering plant!");
            }

            currentSession.StatusId  = 2;
            currentSession.StartTime = now;
            currentSession.Update();
        }
Beispiel #2
0
        public void StartWatering(int tapMangoPlantId)
        {
            var now = DateTime.Now;
            //var timeRemaining = 0m;
            var tapMangoPlant  = TapMangoPlant.GetById(tapMangoPlantId);
            var currentSession = tapMangoPlant.Sessions.FirstOrDefault();

            if (currentSession == null)
            {
                CreateNewSession(tapMangoPlant.Id, now);
                //timeRemaining = 10000;
            }
            else if (now > currentSession.ExpectToCompleteOn && currentSession.StatusId == 1)
            {
                if (currentSession.ExpectToCompleteOn.AddSeconds(30) > now)
                {
                    throw new Exception("Plant need to rest!");
                }

                CreateNewSession(tapMangoPlant.Id, now);
                //timeRemaining = 10000;
            }
            else
            {
                if (currentSession.StatusId == 1)
                {
                    throw new Exception("You are already watering this plant!");
                }

                var difference = currentSession.ExpectToCompleteOn - currentSession.StartTime;

                currentSession.StatusId           = 1;
                currentSession.StartTime          = now;
                currentSession.ExpectToCompleteOn = now + difference;
                currentSession.Update();

                //timeRemaining = Convert.ToDecimal(difference.Ticks) / 10000;
            }

            //return timeRemaining;
        }