public async Task <IActionResult> GetAllRuuviStations() { var stations = await GetAllObjectsAsync(); stations.ForEach(station => station.Tags.RemoveAll(tag => tag.IsActive != true)); // Shows only the active tags if (stations != null) { List <RuuviStationReadDto> listStationDtos = new List <RuuviStationReadDto>(); foreach (var station in stations) { var stationDto = this._mapper.Map <RuuviStationReadDto>(station); var serviceAgreement = new ServiceAgreementConfiguration(station, this._repositoryAgreement, this._serviceAgreementRepository); var serviceGeometric = new ServiceGeometricConfiguration(station, this._repositoryGeometric, this._serviceGeometricRepository); List <ServiceAgreement> breachedAgreements = await serviceAgreement.IsBreachedCollection(); List <ServiceGeometric> breachedGeometrics = await serviceGeometric.IsBreachedCollection(); stationDto.ServiceAgreements = breachedAgreements; stationDto.ServiceGeometrics = breachedGeometrics; listStationDtos.Add(stationDto); } return(Ok(listStationDtos)); } return(NotFound()); }
public async Task <IActionResult> UpdateRuuviStationByDeviceId(string id, RuuviStationCreateDto stationCreateDto) { var stationModel = this._mapper.Map <RuuviStation>(stationCreateDto); var stations = await GetAllObjectsAsync(); var station = stations.Find(doc => doc.DeviceId == id); if (station != null) { stationModel.UpdatedAt = DateTime.UtcNow; stationModel.Id = new ObjectId(id); stationModel.Tags.ForEach(tag => tag.UpdateAt = DateTime.UtcNow); this._repositoryRuuviStation.UpdateObject(id, stationModel); var ruuviStationReadDto = this._mapper.Map <RuuviStationReadDto>(station); var serviceAgreement = new ServiceAgreementConfiguration(station, this._repositoryAgreement, this._serviceAgreementRepository); var serviceGeometric = new ServiceGeometricConfiguration(station, this._repositoryGeometric, this._serviceGeometricRepository); List <ServiceAgreement> breachedAgreements = await serviceAgreement.IsBreachedCollection(); List <ServiceGeometric> breachedGeometrics = await serviceGeometric.IsBreachedCollection(); ruuviStationReadDto.ServiceAgreements = breachedAgreements; ruuviStationReadDto.ServiceGeometrics = breachedGeometrics; await this._hub.Clients.All.SendAsync("GetNewRuuviStations", ruuviStationReadDto); return(Ok(ruuviStationReadDto)); } return(NotFound()); }
public async Task <IActionResult> CreateRuuviStation(RuuviStationCreateDto ruuviStationCreateDto) { var station = this._mapper.Map <RuuviStation>(ruuviStationCreateDto); station.Tags.ForEach(tag => tag.CreateDate = DateTime.UtcNow); station.Tags.ForEach(tag => tag.UpdateAt = DateTime.UtcNow); station.Tags.ForEach(tag => tag.IsActive = true); await this._repositoryRuuviStation.CreateObjectAsync(station); var ruuviStationReadDto = this._mapper.Map <RuuviStationReadDto>(station); var serviceAgreement = new ServiceAgreementConfiguration(station, this._repositoryAgreement, this._serviceAgreementRepository); var serviceGeometric = new ServiceGeometricConfiguration(station, this._repositoryGeometric, this._serviceGeometricRepository); List <ServiceAgreement> breachedAgreements = await serviceAgreement.IsBreachedCollection(); List <ServiceGeometric> breachedGeometrics = await serviceGeometric.IsBreachedCollection(); ruuviStationReadDto.ServiceAgreements = breachedAgreements; ruuviStationReadDto.ServiceGeometrics = breachedGeometrics; await this._hub.Clients.All.SendAsync("GetNewRuuviStations", ruuviStationReadDto); return(CreatedAtRoute(nameof(GetRuuviStationByDeviceId), new { Id = ruuviStationReadDto.Id }, ruuviStationReadDto)); }
public async Task <IActionResult> GetAllByDeviceId(string id) { var stations = await this._repositoryRuuviStation.GetAllAsync(); stations = stations.FindAll(doc => doc.DeviceId == id).ToList(); if (stations != null) { List <RuuviStationReadDto> listStationDtos = new List <RuuviStationReadDto>(); foreach (var station in stations) { var stationDto = this._mapper.Map <RuuviStationReadDto>(station); var serviceAgreement = new ServiceAgreementConfiguration(station, this._repositoryAgreement, this._serviceAgreementRepository); var serviceGeometric = new ServiceGeometricConfiguration(station, this._repositoryGeometric, this._serviceGeometricRepository); List <ServiceAgreement> breachedAgreements = await serviceAgreement.IsBreachedCollection(); List <ServiceGeometric> breachedGeometrics = await serviceGeometric.IsBreachedCollection(); stationDto.ServiceAgreements = breachedAgreements; stationDto.ServiceGeometrics = breachedGeometrics; listStationDtos.Add(stationDto); } return(Ok(listStationDtos)); } return(NotFound()); }
public async Task <IActionResult> GetValadatedDeviceById(string id) { var stations = await GetAllObjectsAsync(); var station = stations.Find(doc => doc.DeviceId == id); if (station != null) { var geometricAgreement = new ServiceGeometricConfiguration(station, this._geometricRepository, this._serviceGeometricRepository); var breachedStations = await geometricAgreement.IsBreachedCollection(); return(Ok(_mapper.Map <IEnumerable <ServiceGeometricReadDto> >(breachedStations))); } return(NotFound()); }
private async void SendRuuviStation(RuuviStation station) { // XXX: Duplicate code present in controller... // XXX: Service should be implemented for these kind of methods var ruuviStationReadDto = this._mapper.Map <RuuviStationReadDto>(station); var serviceAgreement = new ServiceAgreementConfiguration(station, this._repositoryAgreement, this._serviceAgreementRepository); var serviceGeometric = new ServiceGeometricConfiguration(station, this._repositoryGeometric, this._serviceGeometricRepository); List <ServiceAgreement> breachedAgreements = await serviceAgreement.IsBreachedCollection(); List <ServiceGeometric> breachedGeometrics = await serviceGeometric.IsBreachedCollection(); ruuviStationReadDto.ServiceAgreements = breachedAgreements; ruuviStationReadDto.ServiceGeometrics = breachedGeometrics; await this._context.Clients.All.SendAsync("GetNewRuuviStations", ruuviStationReadDto); }
public async Task <IActionResult> GetRuuviStationByDeviceId(string id) { var stations = await GetAllObjectsAsync(); var station = stations.Find(doc => doc.DeviceId == id); if (station != null) { var stationDto = this._mapper.Map <RuuviStationReadDto>(station); var serviceAgreement = new ServiceAgreementConfiguration(station, this._repositoryAgreement, this._serviceAgreementRepository); var serviceGeometric = new ServiceGeometricConfiguration(station, this._repositoryGeometric, this._serviceGeometricRepository); List <ServiceAgreement> breachedAgreements = await serviceAgreement.IsBreachedCollection(); List <ServiceGeometric> breachedGeometrics = await serviceGeometric.IsBreachedCollection(); stationDto.ServiceAgreements = breachedAgreements; stationDto.ServiceGeometrics = breachedGeometrics; return(Ok(stationDto)); } return(NotFound()); }