public CustomJsonResult Edit(string operater, RopBackgroundJobEdit rop)
        {
            CustomJsonResult result = new CustomJsonResult();

            if (!QuartzManager.ValidExpression(rop.CronExpression))
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "无效的Cron表达式"));
            }

            var backgroundJob = CurrentDb.BackgroundJob.Where(m => m.Id == rop.Id).FirstOrDefault();

            if (backgroundJob == null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "数据为空"));
            }

            backgroundJob.CronExpression            = rop.CronExpression;
            backgroundJob.CronExpressionDescription = rop.CronExpressionDescription;
            backgroundJob.Description = rop.Description;
            backgroundJob.Mender      = operater;
            backgroundJob.MendTime    = DateTime.Now;

            CurrentDb.SaveChanges();

            result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "操作成功");

            return(result);
        }
        public CustomJsonResult Add(string operater, RopBackgroundJobAdd rop)
        {
            CustomJsonResult result = new CustomJsonResult();

            var isExists = CurrentDb.BackgroundJob.Where(m => m.AssemblyName == rop.AssemblyName && m.ClassName == rop.ClassName).FirstOrDefault();

            if (isExists != null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, string.Format("程序集:{0},类名:{1},已存在")));
            }

            var type = QuartzManager.GetClassInfo(rop.AssemblyName, rop.ClassName);

            if (type == null)
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "程序集或类型无效,无法映射"));
            }

            if (!QuartzManager.ValidExpression(rop.CronExpression))
            {
                return(new CustomJsonResult(ResultType.Failure, ResultCode.Failure, "无效的Cron表达式"));
            }

            var backgroundJob = new BackgroundJob();

            backgroundJob.Id                        = GuidUtil.New();
            backgroundJob.Name                      = rop.Name;
            backgroundJob.AssemblyName              = rop.AssemblyName;
            backgroundJob.ClassName                 = rop.ClassName;
            backgroundJob.CronExpression            = rop.CronExpression;
            backgroundJob.CronExpressionDescription = rop.CronExpressionDescription;
            backgroundJob.Description               = rop.Description;
            backgroundJob.DisplayOrder              = 0;
            backgroundJob.RunCount                  = 0;
            backgroundJob.Status                    = Enumeration.BackgroundJobStatus.Stoped;
            backgroundJob.IsDelete                  = false;
            backgroundJob.Creator                   = operater;
            backgroundJob.CreateTime                = DateTime.Now;


            CurrentDb.BackgroundJob.Add(backgroundJob);
            CurrentDb.SaveChanges();


            result = new CustomJsonResult(ResultType.Success, ResultCode.Success, "操作成功");

            return(result);
        }