public object DeleteFunction([FromBody] AdAppFunction obj)
        {
            try
            {
                //_logger.LogInformation(LoggingEvents.LogDb, "Delete Function of Application");
                var dataAppFunction = _context.AdAppFunctions.Where(p => p.Function.ParentCode == obj.FunctionCode && p.ApplicationCode == obj.ApplicationCode);
                if (dataAppFunction.Any())
                {
                    //_logger.LogError(LoggingEvents.LogDb, "Delete function fail");
                    _actionLog.InsertActionLog("VIB_APP_FUNCTION", "Delete function fail", null, null, "Error");

                    return(Json(new JMessage()
                    {
                        Error = true, Title = String.Format(CommonUtil.ResourceValue("MSG_DELETE_CHILD"), CommonUtil.ResourceValue("FUNCTION"))
                    }));
                }

                var vibAppFunc = _context.AdAppFunctions.FirstOrDefault(x => x.ApplicationCode == obj.ApplicationCode && x.FunctionCode == obj.FunctionCode);
                if (vibAppFunc != null)
                {
                    _context.Remove(vibAppFunc);
                }
                _context.SaveChanges();
                //_logger.LogInformation(LoggingEvents.LogDb, "Delete function successfully");
                _actionLog.InsertActionLog("VIB_APP_FUNCTION", "Delete function successfully", null, null, "Delete");

                return(Json(new JMessage()
                {
                    Error = false, Title = String.Format(CommonUtil.ResourceValue("MSG_DELETE_SUCCESS"), CommonUtil.ResourceValue("FUNCTION"))
                }));
            }
            catch (Exception ex)
            {
                //_logger.LogError(LoggingEvents.LogDb, "Delete function fail");
                _actionLog.InsertActionLog("VIB_APP_FUNCTION", "Delete function failed: " + ex.Message, null, null, "Error");

                return(Json(new JMessage()
                {
                    Error = true, Title = String.Format(CommonUtil.ResourceValue("MSG_DELETE_FAIL"), CommonUtil.ResourceValue("FUNCTION"))
                }));
            }
        }
        public async Task <JsonResult> InsertFunction([FromBody] AppFuncModel obj)
        {
            var msg = new JMessage()
            {
                Error = false
            };

            try
            {
                var app = _context.AdApplications.Where(p => p.ApplicationCode == obj.ApplicationCode).AsNoTracking().SingleOrDefault();
                if (app != null)
                {
                    // Add function
                    if (obj.FunctionAdd != null && obj.FunctionAdd.Count > 0)
                    {
                        foreach (var funcCode in obj.FunctionAdd)
                        {
                            var function = await _context.AdFunctions.FirstOrDefaultAsync(x => x.FunctionCode == funcCode);

                            if (function != null)
                            {
                                var appFunc = await _context.AdAppFunctions.FirstOrDefaultAsync(x => x.ApplicationCode == app.ApplicationCode && x.FunctionCode == funcCode);

                                if (appFunc == null)
                                {
                                    appFunc = new AdAppFunction();
                                    appFunc.ApplicationCode = app.ApplicationCode;
                                    appFunc.FunctionCode    = function.FunctionCode;
                                    _context.Add(appFunc);
                                }
                            }
                        }
                    }
                    // Remove function
                    if (obj.FunctionDel != null && obj.FunctionDel.Count > 0)
                    {
                        foreach (var funcCode in obj.FunctionDel)
                        {
                            var function = await _context.AdFunctions.FirstOrDefaultAsync(x => x.FunctionCode == funcCode);

                            if (function != null)
                            {
                                var appFunc = await _context.AdAppFunctions.FirstOrDefaultAsync(x => x.ApplicationCode == app.ApplicationCode && x.FunctionCode == funcCode);

                                if (appFunc != null)
                                {
                                    _context.Remove(appFunc);
                                }
                            }
                        }
                    }
                    await _context.SaveChangesAsync();

                    msg.Title = "Cập nhập chức năng cho ứng dụng thành công";
                    _actionLog.InsertActionLog("VIB_APP_FUNCTION", "Update function to application successfully", null, null, "Update");
                }
                else
                {
                    msg.Error = true;
                    msg.Title = "Ứng dụng đã tồn tại!";
                    //_logger.LogError(LoggingEvents.LogDb, "Insert function fail");
                }
            }
            catch (Exception ex)
            {
                msg.Error = true;
                msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_FAIL"), CommonUtil.ResourceValue("FUNCTION")); //"Có lỗi khi thêm chức năng";
                //_logger.LogError(LoggingEvents.LogDb, "Insert function fail");
                _actionLog.InsertActionLog("VIB_APP_FUNCTION", "Update function to application failed: " + ex.Message, null, null, "Error");
            }
            return(Json(msg));
        }