Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateStation(string id, StationCreateDto stationCreateDto)
        {
            var stationModel = this._mapper.Map <Station>(stationCreateDto);
            var station      = await this._repository.GetObjectByIdAsync(id);

            if (station != null)
            {
                stationModel.UpdatedAt = DateTime.UtcNow;
                stationModel.Id        = new ObjectId(id);
                this._repository.UpdateObject(id, stationModel);

                return(Ok(_mapper.Map <StationReadDto>(stationModel)));
            }

            return(NotFound());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreateStation(StationCreateDto stationCreateDto)
        {
            var station = this._mapper.Map <Station>(stationCreateDto);

            if (station != null)
            {
                station.Id        = ObjectId.GenerateNewId();
                station.CreatedAt = station.UpdatedAt = DateTime.UtcNow;
                await this._repository.CreateObjectAsync(station);

                // SignalR event
                // await this._hub.Clients.All.SendAsync("GetNewStationsAsync", station);

                return(Ok(this._mapper.Map <StationReadDto>(station)));
            }

            return(NotFound());
        }