public ActionResult DeleteConfirmed(long id, int?page, string ipp)
        {
            GLaccounts gLaccounts       = db.GLaccounts.Find(id);
            hidServices <GLaccounts> hs = new hidServices <GLaccounts>(db);
            hidServices <GLaccounts> hh = new hidServices <GLaccounts>(db);

            try
            {
                hh.delete(id.ToString());
            }
            catch (Exception ex)
            {
                TempData["ExclError"] = "Error deleting: " + ex.Message;
                //ModelState.AddModelError("", "Erro na remoção: " + ex.Message);
                return(RedirectToAction("Index", new { page = (Request.QueryString["page"] ?? (string)Session["DefaultItemsPerPage"]), ipp = (Request.QueryString["ipp"] ?? (string)Session["DefaultItemsPerPage"]) }));
            }
            int pageNumber = (page ?? 1);

            ipp = ipp ?? (string)Session["DefaultItemsPerPage"];
            ArrayList recolhidas = (ArrayList)Session["ContasCollapsedList"];
            string    wc         = hs.WhereClause(recolhidas);
            var       result     = db.Database.SqlQuery <GLaccounts>("select * from GLaccounts where " + wc + " order by hid").ToList(); // Sql server only

            //var result = db.GLaccounts.OrderBy(c => c.hid).ToList().Where(c => c.IsNotCollapsed(hs, recolhidas));
            return(View("Index", result.ToPagedList(pageNumber, int.Parse(ipp))));
        }
        // GET: GLaccounts/Create
        public ActionResult Create(int?page, string ipp)
        {
            var mae = Session["itemSelecionado"] as String;
            hidServices <GLaccounts> hs = new hidServices <GLaccounts>(db);

            if (!hs.RootExists())
            {
                ViewBag.mensagem = "As root account";
            }
            else
            {
                try
                {
                    GLaccounts r = db.GLaccounts.Find(long.Parse(mae));
                    ViewBag.mensagem = "As last child of account " + mae + " (" + r.Name + ")";
                }
                catch (Exception)
                {
                    mae = "";
                }
                if (string.IsNullOrEmpty(mae))
                {
                    ModelState.AddModelError("", "Root exists. Please select parent account.");
                    ArrayList recolhidas = (ArrayList)Session["ContasCollapsedList"];
                    string    wc         = hs.WhereClause(recolhidas);
                    var       result     = db.Database.SqlQuery <GLaccounts>("select * from GLaccounts where " + wc + " order by hid").ToList(); // Sql server only
                    //var result = db.GLaccounts.OrderBy(c => c.hid).ToList().Where(c => c.IsNotCollapsed(hs, recolhidas));
                    int pageNumber = (page ?? 1);
                    ipp = ipp ?? (string)Session["DefaultItemsPerPage"];
                    return(View("Index", result.ToPagedList(pageNumber, int.Parse(ipp))));
                }
            }
            return(View());
        }
        // GET: GLaccounts/Delete/5
        public ActionResult Delete(long?id, int?page, string ipp)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GLaccounts gLaccounts = db.GLaccounts.Find(id);

            if (gLaccounts == null)
            {
                return(HttpNotFound());
            }
            return(View(gLaccounts));
        }
        // GET: GLaccounts/Edit/5
        public ActionResult Edit(long?id, int?page, string ipp)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GLaccounts contas = db.GLaccounts.Find(id);

            TempData["hid"] = contas.hid;
            if (contas == null)
            {
                return(HttpNotFound());
            }
            return(View(contas));
        }
 public ActionResult Edit([Bind(Include = "Account,Name,hid")] GLaccounts gLaccounts, int?page, string ipp)
 {
     if (ModelState.IsValid)
     {
         gLaccounts.hid             = (byte[])TempData["hid"];
         db.Entry(gLaccounts).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         int pageNumber = (page ?? 1);
         ipp = ipp ?? (string)Session["DefaultItemsPerPage"];
         ArrayList recolhidas        = (ArrayList)Session["ContasCollapsedList"];
         hidServices <GLaccounts> hs = new hidServices <GLaccounts>(db);
         var result = db.GLaccounts.OrderBy(c => c.hid).ToList().Where(c => c.IsNotCollapsed(hs, recolhidas));
         return(View("Index", result.ToPagedList(pageNumber, int.Parse(ipp))));
     }
     return(View(gLaccounts));
 }
 public ActionResult Edit([Bind(Include = "Account,Name, ClauseText, NonComplianceText, RemedialActionText,hid")] GLaccounts gLaccounts, int?page, string ipp)
 {
     if (ModelState.IsValid)
     {
         gLaccounts.hid             = (byte[])TempData["hid"];
         db.Entry(gLaccounts).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         int pageNumber = (page ?? 1);
         ipp = ipp ?? (string)Session["DefaultItemsPerPage"];
         ArrayList recolhidas        = (ArrayList)Session["ContasCollapsedList"];
         hidServices <GLaccounts> hs = new hidServices <GLaccounts>(db);
         string wc     = hs.WhereClause(recolhidas);
         var    result = db.Database.SqlQuery <GLaccounts>("select * from GLaccounts where " + wc + " order by hid").ToList(); // Sql server only
         //var result = db.GLaccounts.OrderBy(c => c.hid).ToList().Where(c => c.IsNotCollapsed(hs, recolhidas));
         return(View("Index", result.ToPagedList(pageNumber, int.Parse(ipp))));
     }
     return(View(gLaccounts));
 }
        public ActionResult HCommand(GLaccounts conta, int?page, string ipp, string refresh, string promote, string up, string down, string demote)
        {
            hidServices <GLaccounts> hs = new hidServices <GLaccounts>(db);

            if (string.IsNullOrEmpty(refresh))
            {
                var pk = Session["itemSelecionado"] as String;
                try
                {
                    if (!string.IsNullOrEmpty(promote))
                    {
                        hs.Command(pk, hidServices <GLaccounts> .Commands.Promote);
                    }
                    if (!string.IsNullOrEmpty(up))
                    {
                        hs.Command(pk, hidServices <GLaccounts> .Commands.Up);
                    }
                    if (!string.IsNullOrEmpty(down))
                    {
                        hs.Command(pk, hidServices <GLaccounts> .Commands.Down);
                    }
                    if (!string.IsNullOrEmpty(demote))
                    {
                        hs.Command(pk, hidServices <GLaccounts> .Commands.Demote);
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }
            ArrayList recolhidas = (ArrayList)Session["ContasCollapsedList"];

            db = new GLaccountsModel();                                                                                           // to refresh entity after sql command
            string wc     = hs.WhereClause(recolhidas);
            var    result = db.Database.SqlQuery <GLaccounts>("select * from GLaccounts where " + wc + " order by hid").ToList(); // Sql server only
            //var result = db.GLaccounts.OrderBy(c => c.hid).ToList().Where(c => c.IsNotCollapsed(hs, recolhidas));
            int pageNumber = page ?? 1;

            ipp = ipp ?? (string)Session["DefaultItemsPerPage"];
            return(View("Index", result.ToPagedList(pageNumber, int.Parse(ipp))));
        }
        // GET: GLaccounts/Details/5
        public ActionResult Details(long?id, int?page, string ipp)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GLaccounts contas = db.GLaccounts.Find(id);

            if (contas == null)
            {
                return(HttpNotFound());
            }
            ArrayList recolhidas        = (ArrayList)Session["ContasCollapsedList"];
            hidServices <GLaccounts> hs = new hidServices <GLaccounts>(db);
            var result     = db.GLaccounts.OrderBy(c => c.hid).ToList().Where(c => c.IsNotCollapsed(hs, recolhidas));
            int pageNumber = page ?? 1;

            ipp = ipp ?? (string)Session["DefaultItemsPerPage"];
            return(View(contas));
        }
        public ActionResult Create([Bind(Include = "Account,Name,hid")] GLaccounts gLaccounts, int?page, string ipp)
        {
            int pageNumber = (page ?? 1);

            ipp = ipp ?? (string)Session["DefaultItemsPerPage"];
            if (ModelState.IsValid)
            {
                var mae = Session["itemSelecionado"] as String;
                hidServices <GLaccounts> hs = new hidServices <GLaccounts>(db);

                gLaccounts.hid = hs.GetNextSonHid(mae);
                db.GLaccounts.Add(gLaccounts);
                db.SaveChanges();
                //gLaccounts.InsertNewConta(gLaccounts.Name, mae);
                ArrayList recolhidas = (ArrayList)Session["ContasCollapsedList"];
                var       result     = db.GLaccounts.OrderBy(c => c.hid).ToList().Where(c => c.IsNotCollapsed(hs, recolhidas));
                return(View("Index", result.ToPagedList(pageNumber, int.Parse(ipp))));
            }
            return(View(gLaccounts));
        }
        // GET: GLaccounts/Details/5
        public ActionResult Details(long?id, int?page, string ipp)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GLaccounts contas = db.GLaccounts.Find(id);

            if (contas == null)
            {
                return(HttpNotFound());
            }
            ArrayList recolhidas        = (ArrayList)Session["ContasCollapsedList"];
            hidServices <GLaccounts> hs = new hidServices <GLaccounts>(db);
            string wc     = hs.WhereClause(recolhidas);                                                                           // Sql server only
            var    result = db.Database.SqlQuery <GLaccounts>("select * from GLaccounts where " + wc + " order by hid").ToList(); // Sql server only
            //var result = db.GLaccounts.OrderBy(c => c.hid).ToList().Where(c => c.IsNotCollapsed(hs, recolhidas));
            int pageNumber = page ?? 1;

            ipp = ipp ?? (string)Session["DefaultItemsPerPage"];
            return(View(contas));
        }
        public ActionResult LinhaSelecionada(String id, int?page, string ipp)
        {
            GLaccounts contas = db.GLaccounts.Find(long.Parse(id));

            if (contas == null)
            {
                return(HttpNotFound());
            }

            if ((String)Session["itemSelecionado"] == contas.Account.ToString())
            {
                Session["itemSelecionado"] = "";
            }
            else
            {
                Session["itemSelecionado"] = contas.Account.ToString();
            }

            string url = Url.Content("~/GLaccounts/Index/");

            return(Json(url + "?page=" + page.ToString() + "&ipp=" + ipp));
        }
        public ActionResult Create([Bind(Include = "Account, Name, ClauseText, NonComplianceText, RemedialActionText, hid")] GLaccounts gLaccounts, int?page, string ipp)
        {
            int pageNumber = (page ?? 1);

            ipp = ipp ?? (string)Session["DefaultItemsPerPage"];
            if (ModelState.IsValid)
            {
                var mae = Session["itemSelecionado"] as String;
                hidServices <GLaccounts> hs = new hidServices <GLaccounts>(db);

                gLaccounts.hid = hs.GetNextSonHid(mae);
                db.GLaccounts.Add(gLaccounts);
                db.SaveChanges();
                //gLaccounts.InsertNewConta(gLaccounts.Name, mae);
                ArrayList recolhidas = (ArrayList)Session["ContasCollapsedList"];
                string    wc         = hs.WhereClause(recolhidas);
                var       result     = db.Database.SqlQuery <GLaccounts>("select * from GLaccounts where " + wc + " order by hid").ToList(); // Sql server only
                //var result = db.GLaccounts.OrderBy(c => c.hid).ToList().Where(c => c.IsNotCollapsed(hs, recolhidas));
                return(View("Index", result.ToPagedList(pageNumber, int.Parse(ipp))));
            }
            return(View(gLaccounts));
        }