Exemple #1
0
        public async Task <RedirectToActionResult> DeleteSubmode(Guid id)
        {
            //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)
            {
                Mode m = current.LastMode.Mode;
                try
                {
                    _session.BeginTransaction();
                    Guid scan_id = await _session.GetScanID(id);

                    await _session.DeleteAntennaScanUsingScanID(scan_id);

                    await _session.DeleteScan(scan_id);

                    await _session.DeleteSubMode(id);

                    await _session.Commit();

                    current.message = "Submode " + id + "removed from database";
                }
                catch (Exception e)
                {
                    // log exception here
                    current.message = e.Message.ToString() + " Error";
                    await _session.Rollback();
                }
                finally
                {
                    _session.CloseTransaction();
                }

                return(RedirectToAction("BeforeEdit", "Mode", new { id = m.ID }));
            }
            return(RedirectToAction("RadarList", "AdminRadarList"));
        }
        public async Task <RedirectToActionResult> DeleteRadar()
        {
            //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);

            try
            {
                _session.BeginTransaction();
                await _session.DeleteScan(current.Radar.ID);

                await _session.DeleteLocation(current.Location.ID);

                await _session.DeleteReceiver(current.Receiver.ID);

                await _session.DeleteTransmitter(current.Transmitter.ID);

                await _session.DeleteLocation(current.Location.ID);

                await _session.Commit();

                current.message = "Radar " + current.Radar.ID + " removed From Database";
            }
            catch (Exception e)
            {
                // log exception here
                current.message = e.Message.ToString() + " Error";
                await _session.Rollback();
            }
            finally
            {
                _session.CloseTransaction();
            }
            return(RedirectToAction("RadarList", "AdminRadarList"));
        }