public async Task <IActionResult> Edit(Antenna antenna) { //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); //control if current did not came if (current == null) { //error return(RedirectToAction("BeforeEdit", "Antenna", new { id = antenna.ID })); } //update our data class //this way is not so effective if I can find a more effective way I will change it for (int i = 0; i < current.ListOfAntennas.Count; i++) { if (current.ListOfAntennas[i].ID.Equals(antenna.ID)) { current.ListOfAntennas[i] = antenna; } } //update database try { await _session.EditAntenna(antenna.ID, antenna.name, antenna.type, antenna.horizontal_beamwidth, antenna.vertical_beamwidth, antenna.polarization, antenna.number_of_feed, antenna.horizontal_dimension, antenna.vertical_dimension, antenna.location); ViewData["message"] = "Antenna updated succesfully"; } catch (Exception e) { // log exception here ViewData["message"] = e.Message.ToString() + " Error"; await _session.Rollback(); } finally { _session.CloseTransaction(); } current.edited = true; return(RedirectToAction("BeforeEdit", "Antenna", new { id = antenna.ID })); }