public async Task <Outcome <Sensor> > Update(int sensorId, StateDto stateDto) { var result = new Outcome <Sensor>(); if (!Enum.GetNames(typeof(SensorState)).Any(x => x.Equals(stateDto.State, StringComparison.InvariantCultureIgnoreCase))) { result.ErrorMessage = "State is not valid"; return(result); } var sensor = _uow.Repository <Sensor>().GetEntityWithSpec(new SensorSpecifications(a => a.SensorId == sensorId)).Result; if (sensor != null) { var auditData = _auditDataProvider.GetAuditList(DateTime.Now.Date, string.Empty, "Sensors", sensor.Farm.Name, sensor.SensorId); if (auditData != null && auditData.Any()) { sensor.RecordFlag = "Error"; } var state = Enum.GetNames(typeof(SensorState)).FirstOrDefault(x => x.Equals(stateDto.State, StringComparison.InvariantCultureIgnoreCase)); sensor.State = (SensorState)Enum.Parse(typeof(SensorState), state); sensor.UpdateDt = DateTime.Now; _uow.Repository <Sensor>().Update(sensor); int output = await _uow.Complete(); result.Result = sensor; } else { result.ErrorMessage = "Sensor not found"; } return(result); }
public async Task <Outcome <Cow> > Update(int cowId, StateDto stateDto) { var result = new Outcome <Cow>(); if (!Enum.GetNames(typeof(CowState)).Any(x => x.Equals(stateDto.State, StringComparison.InvariantCultureIgnoreCase))) { result.ErrorMessage = "State is not valid"; return(result); } var cowSpecification = new CowSpecifications(a => a.CowId == cowId); var cow = await _uow.Repository <Cow>().GetEntityWithSpec(cowSpecification); if (cow != null) { var auditData = _auditDataProvider.GetAuditList(DateTime.Now.Date, string.Empty, "Cows", cow.Farm.Name, cow.CowId); if (auditData != null && auditData.Any()) { cow.RecordFlag = "Error"; } var state = Enum.GetNames(typeof(CowState)).FirstOrDefault(x => x.Equals(stateDto.State, StringComparison.InvariantCultureIgnoreCase)); cow.State = (CowState)Enum.Parse(typeof(CowState), state); cow.UpdateDt = DateTime.Now; _uow.Repository <Cow>().Update(cow); int output = await _uow.Complete(); result.Result = cow; } else { result.ErrorMessage = "Cow not found"; } return(result); }
public async Task <ActionResult <List <Audit> > > GetAuditList(DateTime?onDate, string state, string searchType, string farm) { var auditList = await Task.FromResult(auditDataProvider.GetAuditList(onDate, state, searchType, farm)); return(Ok(auditList)); }