Esempio n. 1
0
        public async Task <IActionResult> NewModeAsync(Mode mod)
        {
            Guid key = Guid.NewGuid();

            //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);
            Mode     m  = new Mode(key, mod.name, current.Radar.ID);
            ModeInfo mi = new ModeInfo(m);

            mi.ListOfSubmodes = new List <SubModeInfo>();
            current.LastMode  = mi;

            try
            {
                _session.BeginTransaction();
                await _session.SaveMode(m);

                await _session.Commit();

                current.message = "New Mode added";
            }
            catch (Exception e)
            {
                // log exception here
                current.message = e.Message.ToString() + " Error";
                await _session.Rollback();

                return(View(mod));
            }
            finally
            {
                _session.CloseTransaction();
            }
            return(RedirectToAction("NewSubmode", "Submode"));
        }