using ProductionLineMonitor.Core.Dtos; using ProductionLineMonitor.Core.IRepositories; using ProductionLineMonitor.Core.Models; using System; using System.Collections.Generic; using System.Linq; namespace ProductionLineMonitor.EntityFramework.Repositories { public class SpcRepository : BaseRepository, ISpcRepository { public SpcRepository(ProductionLineContext context) : base(context) { } public void CreateSpc(string machineId, string lasermark, float[] values) { var spc = new Spc() { MachineId = machineId, Lasermark = lasermark }; _entities.Add(spc); } public IEnumerable GetSpcs(string machineId, DateTime startTime, DateTime endTime) { List dtos = new List(); var models = _entities.Where(x => x.DataTime >= startTime && x.DataTime < endTime).OrderBy(x => x.DataTime); foreach (var item in models) { SpcDto dto = new SpcDto { DataTime = item.DataTime, MachineId = machineId, Lasermark = item.Lasermark }; string[] modelValues = item.Values.Split(','); float[] dtoValues = new float[modelValues.Length]; for (int i = 0; i < modelValues.Length; i++) { dtoValues[i] = Convert.ToSingle(modelValues[i]); } dto.Values = dtoValues; dtos.Add(dto); } return dtos; } } }