Exemple #1
0
        private async Task <IActionResult> UpdateStates(int IdCar)
        {
            AccuListWithTime accu = await carCheckingService.GetAccuState(IdCar);

            if (accu == null)
            {
                return(NotFound());
            }
            logger.LogDebug($"Start saving time code");
            TimeCodeHistory timeCodeHistory = new TimeCodeHistory(accu.idCar, accu.time);

            _context.TimeCodes.Add(timeCodeHistory);
            await _context.SaveChangesAsync();

            int idTimeCode = timeCodeHistory.Id;

            logger.LogDebug($"Time code saved. Start saving accu history");

            foreach (Accu a in accu.accu)
            {
                _context.AccuStates.Add(new AccuHistory(idTimeCode, a.id, a.name, a.voltage, a.current, a.charge));
            }
            await _context.SaveChangesAsync();

            logger.LogDebug($"Accu history saved");

            return(Ok());
        }
Exemple #2
0
        public async Task <IActionResult> GetUserCars([FromRoute] int IdCar, [FromRoute] int IdAccu)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            string link = "";
            await _context.CarServices.ForEachAsync(cs =>
            {
                if (cs.IdCar == IdCar)
                {
                    link = cs.Link;
                }
            });

            if (link == "")
            {
                return(NotFound());
            }

            realCarService = new RealCarService(link);
            AccuListWithTime response = await realCarService.GetAccuState(IdAccu);

            if (response == null)
            {
                return(NotFound());
            }

            return(Ok(response));
        }
Exemple #3
0
        public async Task <IActionResult> PostCarService([FromBody] AccuListWithTime accu)
        {
            logger.LogDebug($"Start saving car current state");
            if (!ModelState.IsValid)
            {
                logger.LogDebug($"Error: ModelState is not correct");
                return(BadRequest(ModelState));
            }

            logger.LogDebug($"Start saving time code");
            TimeCodeHistory timeCodeHistory = new TimeCodeHistory(accu.idCar, accu.time);

            _context.TimeCodes.Add(timeCodeHistory);
            await _context.SaveChangesAsync();

            int idTimeCode = timeCodeHistory.Id;

            logger.LogDebug($"Time code saved. Start saving accu history");

            foreach (Accu a in accu.accu)
            {
                AccuHistory accuHistory = new AccuHistory(idTimeCode, a.id, a.name, a.voltage, a.current, a.charge);
                _context.AccuStates.Add(accuHistory);
            }
            await _context.SaveChangesAsync();

            logger.LogDebug($"Accu history saved");

            return(Ok());
        }
Exemple #4
0
        public async Task <IActionResult> GetCarAccu([FromRoute] int IdCar, [FromRoute] int IdAccu)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            AccuListWithTime response = await carRequsetService.GetAccuState(IdCar, IdAccu);

            if (response == null)
            {
                return(NotFound());
            }

            return(Ok(response));
        }