public async Task <IActionResult> RoleMenuData_Form(int id = 0)
        {
            var model = new RoleMenuData();

            try
            {
                if (id == 0)
                {
                    model.IdRole = id;
                    return(await Task.Run(() => View(model)));
                }
                else
                {
                    model = await f.RoleMenuData_GetById(id);

                    if (model == null)
                    {
                        return(NotFound());
                    }
                    return(await Task.Run(() => View(model)));
                }
            }
            catch (Exception ex)
            {
                var Error = new ErrorViewModel();
                Error.MessageContent = ex.ToString();
                Error.MessageTitle   = "Error ";
                Error.RequestId      = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
                model.Error          = Error;
                return(await Task.Run(() => View(model)));
            }
        }
        public async Task <IActionResult> RoleMenuData_Search([Bind("IdRole,IdModule,Posisi,IdParent,Urutan,IdMenu")] RoleMenuData data)
        {
            var model = new RoleMenuDataModel();
            var r     = new ErrorViewModel();

            if (ModelState.IsValid)
            {
                try
                {
                    model.ListData = await f.RoleMenuData_GetSearch(data);

                    return(await Task.Run(() => Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "RoleMenuData_Table", model) })));
                }
                catch (Exception ex)
                {
                    r.MessageContent = ex.ToString();
                    r.MessageTitle   = "Error ";
                    r.RequestId      = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
                    model.Error      = r;
                    model.ListData   = await f.RoleMenuData_Get();

                    return(await Task.Run(() => Json(new { isValid = false, message = r.MessageContent, title = r.MessageTitle, html = Helper.RenderRazorViewToString(this, "RoleMenuData_Table", data) })));
                }
            }
            else
            {
                r.MessageContent = "State Model tidak valid";
                r.MessageTitle   = "Error ";
                r.RequestId      = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
                model.Error      = r;
                model.ListData   = await f.RoleMenuData_Get();

                return(await Task.Run(() => Json(new { isValid = false, message = r.MessageContent, title = r.MessageTitle, html = Helper.RenderRazorViewToString(this, "RoleMenuData_Table", model) })));
            }
        }
        public async Task <IActionResult> RoleMenuData()
        {
            Config.ConStr = _configuration.GetConnectionString("Db");
            var model = new RoleMenuDataModel();

            try
            {
                DeviceDetector.SetVersionTruncation(VersionTruncation.VERSION_TRUNCATION_NONE);
                BotParser botParser = new BotParser();
                var       userAgent = Request.Headers["User-Agent"];
                var       result    = DeviceDetector.GetInfoFromUserAgent(userAgent);

                if (string.IsNullOrEmpty(HttpContext.Session.GetString("_UserId")))
                {
                    var model2 = new alertLogin();
                    return(await Task.Run(() => RedirectToAction("SignIn", "Home", model2)));
                }
                else
                {
                    ViewBag.UserId = HttpContext.Session.GetString("_UserId");
                    ViewBag.Device = result.Match.DeviceType.ToString();
                    Console.WriteLine(ViewBag.Device);
                    var search = new RoleMenuData();
                    model.ListData = await f.RoleMenuData_GetSearch(search);

                    return(await Task.Run(() => View(model)));
                }
            }
            catch (Exception ex)
            {
                var Error = new ErrorViewModel();
                Error.MessageContent = ex.ToString();
                Error.MessageTitle   = "Error ";
                Error.RequestId      = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
                model.Error          = Error;
                return(await Task.Run(() => View(model)));
            }
        }
        public async Task <IActionResult> RoleMenuData_Save([Bind("IdRole,IdModule,Posisi,IdParent,Urutan,IdMenu")] RoleMenuData data)
        {
            var r = new ErrorViewModel();

            if (ModelState.IsValid)
            {
                try
                {
                    r = await f.RoleMenuData_Save(data);

                    if (r.MessageStatus == "success")
                    {
                        return(await Task.Run(() => Json(new { isValid = true })));
                    }
                    else
                    {
                        data.Error = r;
                        return(await Task.Run(() => Json(new { isValid = false, message = r.MessageContent, title = r.MessageTitle, html = Helper.RenderRazorViewToString(this, "RoleMenuData_Form", data) })));
                    }
                }
                catch (Exception ex)
                {
                    r.MessageContent = ex.ToString();
                    r.MessageTitle   = "Error ";
                    r.RequestId      = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
                    return(await Task.Run(() => Json(new { isValid = false, message = r.MessageContent, title = r.MessageTitle, html = Helper.RenderRazorViewToString(this, "RoleMenuData_Form", data) })));
                }
            }
            else
            {
                r.MessageContent = "State Model tidak valid";
                r.MessageTitle   = "Error ";
                r.RequestId      = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
                return(await Task.Run(() => Json(new { isValid = false, message = r.MessageContent, title = r.MessageTitle, html = Helper.RenderRazorViewToString(this, "RoleMenuData_Form", data) })));
            }
        }