Example #1
0
        public async Task <IActionResult> NewSubmodeAsync(Submode sm)
        {
            //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);

            for (int i = 0; i < current.ListOfAntennas.Count; i++)
            {
                current.ListOfAntennas[i].IsChecked = false;
            }
            Guid key_submode = Guid.NewGuid();

            //if our submode does not have a user friendly name we give it a default name with the code below.
            String def_name = null;

            if (String.IsNullOrEmpty(sm.name))
            {
                def_name = current.LastMode.Mode.name + "'s submode " + current.LastMode.ListOfSubmodes.Count;
            }
            else
            {
                def_name = sm.name;
            }

            Submode     sbm     = new Submode(key_submode, def_name, current.LastMode.Mode.ID, sm.PRI, sm.PW, sm.max_frequency, sm.min_frequency);
            SubModeInfo sbmINFO = new SubModeInfo(sbm);

            current.LastMode.ListOfSubmodes.Add(sbmINFO);
            //specify current submode as lastSubmode. So it helps us find scanID during creation of antenna scan relationship
            current.LastMode.LastSubmode = sbmINFO;
            return(RedirectToAction("NewScan", "Scan"));
        }
Example #2
0
        //below functions are for display pages
        public async Task <IActionResult> Show(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.Receiver != null) //means current!=null
            {
                //Get mode's informations and shows it in edit page
                Mode mod = await _session.Modes.Where(b => b.ID.Equals(id)).FirstOrDefaultAsync();

                List <SubModeInfo> INFOLIST = new List <SubModeInfo>();
                List <Submode>     sbm_list = await _session.Submode.Where(b => b.mode_id.Equals(id)).ToListAsync();

                foreach (Submode sbm in sbm_list)
                {
                    Scan s = await _session.Scan.Where(b => b.ID.Equals(sbm.scan_id)).FirstOrDefaultAsync();

                    SubModeInfo subModeInfo = new SubModeInfo(sbm, s);
                    INFOLIST.Add(subModeInfo);
                }
                ModeInfo INFO = new ModeInfo();
                INFO.Mode           = mod;
                INFO.ListOfSubmodes = INFOLIST;
                //it is necessary when we are going to submode pages
                current.LastMode = INFO;
                return(View(INFO));
            }
            return(RedirectToAction("RadarList", "UserRadarList"));
        }
        public async Task <IActionResult> Edit(SubModeInfo 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);

            //not necessary to edit current data bc in submode page we will retrieve all scan informations from db again
            try
            {
                await _session.EditScan(newValues.Scan);
            }
            catch (Exception e)
            {
                // log exception here
                if (current != null)
                {
                    current.message = e.Message.ToString() + " Error";
                }
                await _session.Rollback();
            }
            finally
            {
                _session.CloseTransaction();
            }
            if (current != null)
            {
                current.edited = true;
            }
            return(RedirectToAction("BeforeEdit", "Scan", new { id = newValues.Scan.ID }));
        }
Example #4
0
        //below functions are for edit pages
        public async Task <IActionResult> BeforeEdit(Guid id, String?message)
        {
            //error case
            if (!String.IsNullOrEmpty(message as string))
            {
                SubModeInfo modal = new SubModeInfo();
                modal.Submode        = new Submode();
                modal.Scan           = new Scan();
                modal.ListOfAntennas = new List <Antenna>();
                ViewData["Message"]  = message as string;
                return(View(modal));
            }

            //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)
            {
                //Because we use the same view before and after edit process we should handle the view messages with the following conditions
                if (current.edited)
                {
                    ViewData["Message"] = "Update completed successfully";
                    current.edited      = false;
                }
                if (current.message != null)
                {
                    ViewData["Message"] = current.message;
                    current.message     = null;
                }

                //Get submode's informations and shows it in edit page
                Submode sbm = await _session.Submode.Where(b => b.ID.Equals(id)).FirstOrDefaultAsync();

                Scan scan = await _session.Scan.Where(b => b.ID.Equals(sbm.scan_id)).FirstOrDefaultAsync();

                for (int j = 0; j < current.LastMode.ListOfSubmodes.Count; j++)
                {
                    if (current.LastMode.ListOfSubmodes[j].Submode.ID.Equals(id))
                    {
                        //specify current submode as last submode. It helps us in scan pages
                        current.LastMode.LastSubmode = current.LastMode.ListOfSubmodes[j];
                    }
                }

                SubModeInfo modal = new SubModeInfo();
                modal.Submode        = sbm;
                modal.Scan           = scan;
                modal.ListOfAntennas = current.ListOfAntennas;
                return(View(modal));
            }
            return(RedirectToAction("RadarList", "AdminRadarList"));
        }
        //below functions are for edit pages
        public async Task <IActionResult> BeforeEdit(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.Receiver != null)
            {
                //Because we use the same view before and after edit process we should handle the view messages with the following conditions
                if (current.edited)
                {
                    ViewData["Message"] = "Update completed successfully";
                    current.edited      = false;
                }
                if (current.message != null)
                {
                    ViewData["Message"] = current.message;
                    current.message     = null;
                }

                //Get scan's informations and shows it in edit page
                Scan scan = await _session.Scan.Where(b => b.ID.Equals(id)).FirstOrDefaultAsync();

                Submode sbm = await _session.Submode.Where(b => b.scan_id.Equals(id)).FirstOrDefaultAsync();

                SubModeInfo info = new SubModeInfo();
                info.Scan           = scan;
                info.Submode        = sbm;
                info.ListOfAntennas = new List <Antenna>();
                //because we do not have an attribute that specifies if the antenna is checked
                //(because an antenna might be used from a lot of scans)
                //we should find if the antenna is working with this scan using AntennaScan tables
                for (int i = 0; i < current.ListOfAntennas.Count; i++)
                {
                    Guid temp = Guid.Empty;
                    temp = await _session.SelectAntennaScan(current.ListOfAntennas[i].ID, id);

                    if (!temp.Equals(Guid.Empty))
                    {
                        info.ListOfAntennas.Add(current.ListOfAntennas[i]);
                    }
                }
                current.LastMode.LastSubmode = info;
                return(View(info));
            }
            //else
            String message = "Update cannot be completed, please restart the program to solve this issue. If it continues please report it";

            return(RedirectToAction("BeforeEdit", "Submode", new { id = Guid.Empty, message = message }));
        }
Example #6
0
        //below functions are for edit pages
        public async Task <IActionResult> BeforeEdit(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)
            {
                //Because we use the same view before and after edit process we should handle the view messages with the following conditions
                if (current.edited)
                {
                    ViewData["Message"] = "Update completed successfully";
                    current.edited      = false;
                }
                if (current.message != null)
                {
                    ViewData["Message"] = current.message;
                    current.message     = null;
                }

                //Get mode's informations and shows it in edit page
                Mode mod = await _session.Modes.Where(b => b.ID.Equals(id)).FirstOrDefaultAsync();

                List <SubModeInfo> INFOLIST = new List <SubModeInfo>();
                List <Submode>     sbm_list = await _session.Submode.Where(b => b.mode_id.Equals(id)).ToListAsync();

                foreach (Submode sbm in sbm_list)
                {
                    Scan s = await _session.Scan.Where(b => b.ID.Equals(sbm.scan_id)).FirstOrDefaultAsync();

                    SubModeInfo subModeInfo = new SubModeInfo(sbm, s);
                    INFOLIST.Add(subModeInfo);
                }
                ModeInfo INFO = new ModeInfo();
                INFO.Mode           = mod;
                INFO.ListOfSubmodes = INFOLIST;
                //it is necessary when we are going to submode pages
                current.LastMode = INFO;
                return(View(INFO));
            }
            return(RedirectToAction("RadarList", "AdminRadarList"));
        }
Example #7
0
        public async Task <IActionResult> Edit(SubModeInfo 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 j = 0; j < current.LastMode.ListOfSubmodes.Count; j++)
                {
                    if (current.LastMode.ListOfSubmodes[j].Submode.ID.Equals(newValues.Submode.ID))
                    {
                        current.LastMode.ListOfSubmodes[j].Submode = newValues.Submode;
                        //specify current submode as last submode
                        current.LastMode.LastSubmode = current.LastMode.ListOfSubmodes[j];
                    }
                }
                //update the db
                try
                {
                    await _session.EditSubmode(newValues.Submode);
                }
                catch (Exception e)
                {
                    // log exception here
                    current.message = e.Message.ToString() + " Error";
                    await _session.Rollback();
                }
                finally
                {
                    _session.CloseTransaction();
                }
                current.edited = true;
                return(RedirectToAction("BeforeEdit", "Submode", new { id = newValues.Submode.ID }));
            }
            String message = "Update cannot be completed, please restart the program to solve this issue. If it continues please report it";

            return(RedirectToAction("BeforeEdit", "Submode", new { id = newValues.Submode.ID, message = message }));
        }
Example #8
0
        //below functions are for display pages
        public async Task <IActionResult> Show(Guid id, String message)
        {
            //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 (!String.IsNullOrEmpty(message))
            {
                ViewData["message"] = message;
            }

            if (current.Receiver != null)
            {
                //Get submode's informations and shows it in edit page
                Submode sbm = await _session.Submode.Where(b => b.ID.Equals(id)).FirstOrDefaultAsync();

                Scan scan = await _session.Scan.Where(b => b.ID.Equals(sbm.scan_id)).FirstOrDefaultAsync();

                for (int j = 0; j < current.LastMode.ListOfSubmodes.Count; j++)
                {
                    if (current.LastMode.ListOfSubmodes[j].Submode.ID.Equals(id))
                    {
                        //specify current submode as last submode. It helps us in scan pages
                        current.LastMode.LastSubmode = current.LastMode.ListOfSubmodes[j];
                    }
                }

                SubModeInfo modal = new SubModeInfo();
                modal.Submode        = sbm;
                modal.Scan           = scan;
                modal.ListOfAntennas = current.ListOfAntennas;
                return(View(modal));
            }
            return(RedirectToAction("RadarList", "UserRadarList"));
        }