public static bool IsValidSetting(FilterSetting filterSetting)
        {
            // 檢查目標網址(不允許NULL)
            if (filterSetting.CrawlUrl == null ||
                filterSetting.CrawlUrl.Length > limitLenOfUrl ||
                !filterSetting.CrawlUrl.StartsWith(TargetUrlHead))
            {
                return(false);
            }

            // 薪資範圍必須為5~6位數
            if (filterSetting.MinimumWage < 10000 || filterSetting.MaximumWage > 999999)
            {
                return(false);
            }

            // 最高月薪必須大於最低月薪
            if (filterSetting.MaximumWage < filterSetting.MinimumWage)
            {
                return(false);
            }

            // 檢查欲排除的關鍵字
            if (!IsValidString(filterSetting.ExcludeWord, limitLenOfExcludeWord))
            {
                return(false);
            }

            // 檢查欲排除的公司名稱
            if (!IsValidString(filterSetting.IgnoreCompany, limitLenOfIgnoreCompany))
            {
                return(false);
            }

            // 檢查備註
            if (!IsValidString(filterSetting.Remarks, limitLenOfRemark))
            {
                return(false);
            }

            return(true);
        }
        public static string CreateSetting(ApplicationDbContext _context, FilterSetting filterSetting, string UserEmail)
        {
            // 查看設定檔的數量是否已達上限
            List <FilterSetting> filterSettings = _context.FilterSetting.Where(m => m.UserEmail == UserEmail).ToList();

            if (filterSettings.Count > 2)
            {
                return("建立失敗,您的設定數量已達上限!");
            }

            // 在後端進行表單驗證
            if (!IsValidSetting(filterSetting))
            {
                return("系統忙碌中,請稍後再試 >___<");
            }

            // 若通過驗證則創建表單
            filterSetting.UserEmail = UserEmail;
            _context.Add(filterSetting);
            return(null);
        }
        public static string DeleteSetting(ApplicationDbContext _context, string UserEmail, int?id)
        {
            if (id == null)
            {
                return("系統忙碌中,請稍後再試 >___<");
            }

            FilterSetting TargetSetting = _context.FilterSetting.FirstOrDefault(m => m.Id == id);

            if (TargetSetting == null)
            {
                return("系統忙碌中,請稍後再試 >___<");
            }

            // 令管理員以外的用戶只能刪除自己的設定
            if (!UserService.InAdminGroup(UserEmail) && TargetSetting.UserEmail != UserEmail)
            {
                return("系統忙碌中,請稍後再試 >___<");
            }

            _context.FilterSetting.Remove(TargetSetting);
            return(null);
        }