public ActionResult Create(RemoteOnUs remoteSetup)
        {
            ViewBag.Catergories = unitofwork.EntityRepository <GLCategory>().GetAll();
            ViewBag.Branches    = unitofwork.EntityRepository <Branch>().GetAll();
            try
            {
                // TODO: Add insert logic here
                var setups = unitofwork.EntityRepository <RemoteOnUs>().Filter(c => c.Name == remoteSetup.Name ||
                                                                               c.GlAccount.GLAccountName == remoteSetup.GlAccount.GLAccountName);

                if (setups.Count == 0)
                {
                    remoteSetup.GlAccount.GLCode = GenerateGLAccountCode(remoteSetup.GlAccount, remoteSetup.GlAccount.Id);
                    remoteSetup.DateAdded        = DateTime.Now;
                    remoteSetup.DateUpdated      = DateTime.Now;
                    unitofwork.EntityRepository <GLAccount>().Save(remoteSetup.GlAccount);
                    unitofwork.EntityRepository <RemoteOnUs>().Save(remoteSetup);
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError("Name", " Name exists.");
            }
            catch (Exception ex)
            {
            }
            return(View());
        }
        public ActionResult Edit(int id, RemoteOnUs remoteSetup)
        {
            ViewBag.Catergories = unitofwork.EntityRepository <GLCategory>().GetAll();
            ViewBag.Branches    = unitofwork.EntityRepository <Branch>().GetAll();
            // if (ModelState.IsValid)
            {
                try
                {
                    var oldEntity = unitofwork.EntityRepository <RemoteOnUs>().GetById(remoteSetup.Id);
                    remoteSetup.GlAccount.GLCode      = oldEntity.GlAccount.GLCode;
                    remoteSetup.GlAccount.DateUpdated = DateTime.Now;
                    remoteSetup.GlAccount.DateAdded   = oldEntity.GlAccount.DateAdded;
                    remoteSetup.DateAdded             = oldEntity.DateAdded;
                    remoteSetup.DateUpdated           = DateTime.Now;
                    unitofwork.EntityRepository <GLAccount>().Update(remoteSetup.GlAccount, remoteSetup.GlAccount.Id);
                    unitofwork.EntityRepository <RemoteOnUs>().Update(remoteSetup, remoteSetup.Id);

                    return(RedirectToAction("Index"));
                }
                catch (Exception exception)
                {
                    ViewBag.Exception = exception;
                }
            }
            return(View(remoteSetup));
        }
        public HttpResponseMessage UpdateGLAccount(Indexes index)
        {
            //  var id = index.Id.ToString().PadLeft(9, '0');
            var id          = index.Id;
            var accountInDb = _context.RemoteOnUsConfig.FirstOrDefault();

            if (accountInDb != null)
            {
                accountInDb.GLAccountId = id;
            }
            else
            {
                var config = new RemoteOnUs();
                config.GLAccountId = id;

                _context.RemoteOnUsConfig.Add(config);
            }

            _context.SaveChanges();

            const string message = "Remote-On-Us GL Account Updated Successfully";

            return(Request.CreateResponse(HttpStatusCode.OK, message));
        }