Exemplo n.º 1
0
        public async Task <IActionResult> Put(ChargePointRequestModel model)
        {
            var dto = mapper.Map <ChargePointsUpdateDto>(model);

            await chargePointService.Update(dto);

            return(Ok());
        }
Exemplo n.º 2
0
        /// <summary>
        /// PutLocation method
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <ChargePoint> PutLocation(ChargePointRequestModel entity)
        {
            var stationsById = await _chargingStationsDbContext.ChargePoints
                               .Where(x => x.LocationId == entity.LocationId)
                               .ToListAsync();

            if (!stationsById.Any() || !entity.ChargePoints.Any())
            {
                return(new ChargePoint());
            }
            {
                ChargePoint updatedStation = null;
                updatedStation = await UpdateStation(entity, stationsById, updatedStation);

                return(updatedStation);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// UpdateStation method
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="stationsById"></param>
        /// <param name="updatedStation"></param>
        /// <returns></returns>
        private async Task <ChargePoint> UpdateStation(ChargePointRequestModel entity, List <ChargePoint> stationsById, ChargePoint updatedStation)
        {
            foreach (var item in stationsById)
            {
                var currentStation = entity.ChargePoints.FirstOrDefault(x => x.ChargePointId == item.ChargePointId);
                if (currentStation == null)
                {
                    updatedStation        = item;
                    updatedStation.Status = "Removed";
                }
                else
                {
                    updatedStation = new ChargePoint
                    {
                        ChargePointId = currentStation.ChargePointId,
                        FloorLevel    = currentStation.FloorLevel,
                        Status        = currentStation.Status,
                        LastUpdated   = DateTime.Now,
                        LocationId    = entity.LocationId
                    };
                }

                var local = _chargingStationsDbContext.Set <ChargePoint>().Local
                            .FirstOrDefault(entry => entry.ChargePointId.Equals(updatedStation.ChargePointId));

                if (local != null)
                {
                    _chargingStationsDbContext.Entry(local).State = EntityState.Detached;
                }

                _chargingStationsDbContext.Entry(updatedStation).State = EntityState.Modified;
                await _chargingStationsDbContext.SaveChangesAsync();
            }

            return(updatedStation);
        }