public async Task <IActionResult> Edit(ModeInfo newValues) { //get session id (we will use it when updating data and handling errors) String sessionID_s = HttpContext.Session.GetString("Session"); Guid sessionID = Guid.Parse(sessionID_s); Data current = new Data(); Program.data.TryGetValue(sessionID, out current); if (current != null) { //update the class for (int i = 0; i < current.ListOfModes.Count; i++) { if (current.ListOfModes[i].Mode.ID.Equals(newValues.Mode.ID)) { current.ListOfModes[i].Mode = newValues.Mode; } } //update the db try { await _session.EditMode(newValues.Mode); } catch (Exception e) { // log exception here current.message = e.Message.ToString() + " Error"; await _session.Rollback(); } finally { _session.CloseTransaction(); } current.edited = true; } return(RedirectToAction("BeforeEdit", "Mode", new { id = newValues.Mode.ID })); }