Esempio n. 1
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 }));
        }