internal static bool HandleEFMigrationException(Exception ex, HttpServerUtility server, HttpResponse response, HttpContext context)
        {
            var _service      = new EFMigrationService();
            var isEfException = (
                ex.Message.ToLower().Contains("context has changed") ||
                ex.Message.ToLower().Contains("contains no mapped tables") ||
                (ex is System.Data.Entity.Core.EntityCommandExecutionException && ex.InnerException?.Message?.ToLower()?.Contains("invalid column name") == true) ||
                ex is SqlException
                );

            if (isEfException && !_service.IsLatestVersion())
            {
                server.ClearError();

                var routeData = new RouteData();
                routeData.Values.Add("controller", "EFMigrationsManager");

                if (_service.IsAuthorizedUser())
                {
                    routeData.Values.Add("action", "publish");
                }
                else
                {
                    routeData.Values.Add("action", "DbMaintenance");
                }
                HttpContext.Current.Response.RedirectToRoute(routeData.Values);
                return(true);
            }
            return(false);
        }
        public ActionResult Publish(bool isRollback = false)
        {
            var _service = new EFMigrationService();

            if (!_service.IsAuthorizedUser())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            var vm = _service.LoadMigrationDetails(isRollback);

            return(View(vm));
        }
        public ActionResult Publish(EFMigrationDetails entity)
        {
            var _service = new EFMigrationService();

            if (!_service.IsAuthorizedUser())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            if (entity == null || string.IsNullOrWhiteSpace(entity.TargetMigration))
            {
                throw new System.ArgumentException("Invalid Parameters...");
            }

            _service.Update(entity.TargetMigration);

            TempData["StatusMessage"] = entity.IsRollback ? "Database restored successfully." : "Database updated successfully.";
            return(RedirectToAction("Publish", new { isRollback = entity.IsRollback }));
        }