//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 }));
        }
Пример #2
0
        public async Task <IActionResult> NewAntennaScanParamAsync(Antenna.AntennaList ascans)
        {
            //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);

            //control if current did not came
            if (current.Receiver == null) //means current == null
            {
                ViewData["message"] = "Error occured please restart the program";
                return(View(ascans));
            }

            //refresh the list to specify selected antennas
            current.ListOfAntennas = ascans.antennas;
            try
            {
                _session.BeginTransaction();

                for (int i = 0; i < ascans.antennas.Count; i++)
                {
                    Antenna antenna = ascans.antennas[i];

                    AntennaScan ascan = new AntennaScan(antenna.ID, current.LastMode.LastSubmode.Scan.ID);
                    if (antenna.IsChecked)
                    {
                        Guid temp = Guid.Empty;
                        temp = await _session.SelectAntennaScan(current.ListOfAntennas[i].ID, current.LastMode.LastSubmode.Scan.ID);

                        if (temp.Equals(Guid.Empty))
                        {
                            await _session.SaveAntennaScan(ascan);
                        }
                    }
                    else
                    {
                        Guid temp = Guid.Empty;
                        temp = await _session.SelectAntennaScan(current.ListOfAntennas[i].ID, current.LastMode.LastSubmode.Scan.ID);

                        if (!temp.Equals(Guid.Empty))
                        {
                            await _session.DeleteAntennaScan(ascan);
                        }
                    }
                }
                await _session.Commit();

                if (current.Receiver != null) //means current != null
                {
                    current.message = "New Relationship between antennas and scan added";
                }
            }
            catch (Exception e)
            {
                // log exception here
                current.message = e.Message.ToString() + " Error";
                await _session.Rollback();
            }
            finally
            {
                _session.CloseTransaction();
            }
            return(RedirectToAction("Preliminary", "AntennaScan"));
        }