private DashboardViewModels CreateDashboard_Pack23ViewModel(Models.Message deviceMessage) { DashboardViewModels dashboard = new DashboardViewModels(); dashboard.DeviceId = deviceMessage.DeviceId; dashboard.Name = deviceMessage.Device.Name; dashboard.Package = deviceMessage.Data; dashboard.TypePackage = deviceMessage.TypePackage; dashboard.Date = deviceMessage.Date; dashboard.Country = deviceMessage.Country; dashboard.Lqi = deviceMessage.Lqi; dashboard.Bits = deviceMessage.Bits; dashboard.SeqNumber = deviceMessage.SeqNumber; var _fluxoAgua = FromFloatSafe(deviceMessage.FluxoAgua); var _consumoAgua = FromFloatSafe(deviceMessage.ConsumoAgua); dashboard.FluxoAgua = String.Format("{0:0.0}", _fluxoAgua); dashboard.ConsumoAgua = String.Format("{0:0.0}", _consumoAgua); var _display = Consts.GetDisplayTRM10(dashboard.Bits.BAlertaMax, dashboard.Bits.ModoFechado, dashboard.Bits.ModoAberto); dashboard.Modo = _display.DisplayModo; // modo dashboard.Estado = _display.DisplayEstado; // alerta dashboard.EstadoImage = _display.EstadoImage; dashboard.ModoImage = _display.ModoImage; dashboard.Valvula = _display.DisplayValvula; dashboard.EstadoColor = _display.EstadoColor; return(dashboard); }
public IEnumerable <DashboardViewModels> GetReportDataTRM10(string id, int skip = 0, int top = 0, string de = null, string ate = null, OptionalOutTotalCount totalCount = null, bool isCallByGraphic = false) { List <DashboardViewModels> newData = new List <DashboardViewModels>(); IQueryable <Message> reportsQuery = _context.Messages.AsNoTracking().Include(i => i.Device).Where(w => w.DeviceId == id && (w.TypePackage.Equals("23"))).OrderByDescending(o => o.Id); try { if (!de.Equals("null")) { DateTime firstDate = Convert.ToDateTime(de).ToUniversalTime(); reportsQuery = reportsQuery.Where(c => c.OperationDate.Value.Year >= firstDate.Year && c.OperationDate.Value.Month >= firstDate.Month && c.OperationDate.Value.Day >= firstDate.Day); } if (!ate.Equals("null")) { var lastDate = Convert.ToDateTime(ate).ToUniversalTime(); reportsQuery = reportsQuery.Where(c => c.OperationDate.Value.Year <= lastDate.Year && c.OperationDate.Value.Month <= lastDate.Month && c.OperationDate.Value.Day <= lastDate.Day); } if (totalCount != null) { totalCount.Value = reportsQuery.Count(); } if (skip != 0) { reportsQuery = reportsQuery.Skip(skip); } if (top != 0) { reportsQuery = reportsQuery.Take(top); } foreach (var report in reportsQuery) { DashboardViewModels newItem = new DashboardViewModels(); newItem.DeviceId = report.DeviceId; newItem.Name = report.Device.Name; newItem.Package = report.Data; newItem.TypePackage = report.TypePackage; newItem.Date = report.Date; newItem.Country = report.Country; newItem.Lqi = report.Lqi; newItem.Bits = report.Bits; var _fluxoAgua = FromFloatSafe(report.FluxoAgua); var _consumoAgua = FromFloatSafe(report.ConsumoAgua); newItem.FluxoAgua = String.Format("{0:0.0}", _fluxoAgua); newItem.ConsumoAgua = String.Format("{0:0.0}", _consumoAgua); if (!isCallByGraphic) { var _display = Consts.GetDisplayTRM10(newItem.Bits.BAlertaMax, newItem.Bits.ModoFechado, newItem.Bits.ModoAberto); newItem.Modo = _display.DisplayModo; // modo newItem.Estado = _display.DisplayEstado; // alerta newItem.Valvula = _display.DisplayValvula; // válvula newItem.EstadoColor = _display.EstadoColor; } newData.Add(newItem); } return(newData.OrderBy(o => o.Date).ToArray()); } catch (System.Exception ex) { _log.Log("Erro GetReportDataTRM.", ex.Message, true); return(newData); } }