Example #1
0
        public async Task <PlantLogDtoResponse> Handle(GetPlantLogForPlantByIdQuery request,
                                                       CancellationToken cancellationToken)
        {
            var plantLog = await context
                           .Plants
                           .Include(p => p.PlantLogs)
                           .Where(p => p.Id.Equals(request.PlantId))
                           .SelectMany(p => p.PlantLogs)
                           .Where(pl => pl.Id.Equals(request.Id))
                           .SingleOrDefaultAsync(cancellationToken: cancellationToken);

            if (null == plantLog)
            {
                return(new PlantLogDtoResponse
                {
                    Success = false,
                    ErrorMessages =
                    {
                        { nameof(request.Id), new[] { "No entity found" } }
                    }
                });
            }

            return(new PlantLogDtoResponse
            {
                Success = true,
                Data = PlantLogDto.FromDao(plantLog),
            });
        }
Example #2
0
        public async Task <PlantLogDtosResponse> Handle(GetAllPlantLogsQuery request,
                                                        CancellationToken cancellationToken)
        {
            var query = dbContext.PlantLogs.AsQueryable();

            if (Guid.Empty != request.PlantId)
            {
                query = query.Where(pl => pl.PlantId == request.PlantId);
            }

            if (request.PlantLogTypes.Length > 0)
            {
                query = query.Where(pl => request.PlantLogTypes.Contains(pl.PlantLogTypeId));
            }

            if (!string.IsNullOrWhiteSpace(request.LogFilter))
            {
                query = query.Where(pl => pl.Log.Contains(request.LogFilter));
            }

            query = query.Where(pl => pl.DateTime >= request.FromDateTime && pl.DateTime <= request.ToDateTime);

            var results = await query.Select(ps => PlantLogDto.FromDao(ps))
                          .ToListAsync(cancellationToken: cancellationToken);

            return(new PlantLogDtosResponse()
            {
                Success = true,
                Data = results,
            });
        }
Example #3
0
 private void AssertDaoEqualDto(PlantLog plantLog, PlantLogDto plantLogDto)
 {
     Assert.Equal(plantLog.Id, plantLogDto.Id);
     Assert.Equal(plantLog.Log, plantLogDto.Log);
     Assert.Equal(plantLog.DateTime, plantLogDto.DateTime);
     Assert.Equal(plantLog.PlantLogTypeId, plantLogDto.PlantLogTypeId);
     Assert.Equal(plantLog.PlantId, plantLogDto.PlantId);
 }
Example #4
0
 public static PlantLog FromCore(PlantLogDto plantLog)
 {
     return(new PlantLog
     {
         Id = plantLog.Id,
         PlantId = plantLog.PlantId,
         PlantLogTypeId = plantLog.PlantLogTypeId,
         DateTime = plantLog.DateTime,
         Log = plantLog.Log,
     });
 }