public async System.Threading.Tasks.Task <IActionResult> NewReceiver(Receiver receiver) { //create new Data element for our current created radar Data current = new Data(); //I think this method gives the current session id sessionID_s = HttpContext.Session.GetString("Session"); sessionID = Guid.Parse(sessionID_s); //If the receiver name is null we give a default name that specifies its number //because we change the default name after the Radar added we we should keep it in mind to it is a default given name bool IsNamed = false; String rec_name = null; if (String.IsNullOrEmpty(receiver.name)) { int count = 0; try { count = await _session.GetReceiverNumber(); } catch (Exception e) { // log exception here ViewData["Message"] = e.Message.ToString() + " Error"; Program.data.Remove(sessionID); await _session.Rollback(); return(RedirectToAction("NewReceiver", "Receiver")); } finally { _session.CloseTransaction(); } rec_name = "Receiver " + count; //keep it in mind IsNamed = true; } else { rec_name = receiver.name; } Guid key = Guid.NewGuid(); Receiver r = new Receiver(key, rec_name, receiver.listening_time, receiver.rest_time, receiver.recovery_time); r.Isnamed = IsNamed; current.Receiver = r; try { _session.BeginTransaction(); await _session.SaveReceiver(r); await _session.Commit(); current.message = "New Receiver added"; } catch (Exception e) { // log exception here ViewData["Message"] = e.Message.ToString() + " Error"; Program.data.Remove(sessionID); await _session.Rollback(); return(RedirectToAction("NewReceiver", "Receiver")); } finally { _session.CloseTransaction(); } Program.data.Remove(sessionID); Program.data.Add(sessionID, current); return(RedirectToAction("Preliminary", "Antenna")); }