コード例 #1
0
        public async Task <IActionResult> NewScanAsync(Scan scan)
        {
            //get session id (we will use it when updating data and handling errors)
            sessionID_s = HttpContext.Session.GetString("Session");
            sessionID   = Guid.Parse(sessionID_s);
            Data current = new Data();

            Program.data.TryGetValue(sessionID, out current);

            Guid key = Guid.NewGuid();
            //if our scan does not have a user friendly name we give it a default name with the code below.
            String def_name = null;

            if (String.IsNullOrEmpty(scan.name))
            {
                def_name = current.LastMode.LastSubmode.Submode.name + "'s scan";
            }
            else
            {
                def_name = scan.name;
            }
            Scan s = new Scan(key, def_name, scan.type, scan.main_aspect, scan.scan_angle, scan.scan_rate, scan.hits_per_scan);


            current.LastMode.LastSubmode.Scan = s;
            //remember we did not give a scan id to this submode, so we did not add it to db
            current.LastMode.LastSubmode.Submode.scan_id = key;
            Submode sbm = current.LastMode.LastSubmode.Submode;

            try
            {
                _session.BeginTransaction();
                await _session.SaveScan(s);

                await _session.SaveSubMode(sbm);

                await _session.Commit();

                current.message = "Both records (Submode and Scan) added to db";
            }
            catch (Exception e)
            {
                // log exception here
                current.message = e.Message.ToString() + " Error";
                await _session.Rollback();
            }
            finally
            {
                _session.CloseTransaction();
            }

            return(RedirectToAction("Preliminary", "AntennaScan"));
        }