public async Task <ActionResult> AddSensor(SimulatedSensor item, string createButton) { if (createButton.Equals("Cancel")) { return(Redirect(CacheHelper.GetPreviousPage(_cache))); } if (item.HardwareId == null) { item.HardwareId = Guid.NewGuid().ToString(); } if (item.DataType == DataTypeEnum.Motion) { item.InitialValue = true.ToString(); } else if (item.InitialValue == null) { item.InitialValue = ((item.MaxValue - item.MinValue) / 2).ToString(); } var list = await CacheHelper.GetSimulatedSensorListFromCacheAsync(_cache); list.Add(item); await CacheHelper.AddSimulatedSensorListInCacheAsync(_cache, list); return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> Edit(SimulatorViewModel model, string action) { if (action.Equals("Cancel")) { return(Redirect(CacheHelper.GetPreviousPage(_cache))); } var list = await CacheHelper.GetSimulatedSensorListFromCacheAsync(_cache); var item = list.First(t => t.HardwareId.Equals(model.SelectedSensor)); var index = list.IndexOf(item); list.Remove(item); list.Insert(index, model.SensorInEdit); await CacheHelper.AddSimulatedSensorListInCacheAsync(_cache, list); return(RedirectToAction(nameof(Index))); }