コード例 #1
0
        public async Task <IWriterResult> AdminUpdateWorker(AdminPoolWorkerUpdateModel model)
        {
            using (var context = PoolDataContextFactory.CreateContext())
            {
                var worker = await context.Worker.Where(w => w.Id == model.Id).FirstOrDefaultNoLockAsync().ConfigureAwait(false);

                if (worker == null)
                {
                    return(new WriterResult(false, "Worker '{0}' not found.", model.Name));
                }

                worker.Password         = model.Password;
                worker.IsAutoSwitch     = model.IsAutoSwitch;
                worker.TargetDifficulty = model.TargetDifficulty;
                worker.TargetPool       = model.TargetPool;
                await context.SaveChangesAsync().ConfigureAwait(false);

                await CacheService.InvalidateAsync(CacheKey.PoolWorkers(worker.UserId.ToString())).ConfigureAwait(false);

                return(new WriterResult(true, $"Successfully updated worker '{worker.Name}'"));
            }
        }
コード例 #2
0
        public async Task <ActionResult> UpdateWorker(AdminPoolWorkerUpdateModel model)
        {
            if (!ModelState.IsValid)
            {
                var poolconnection = await PoolReader.GetPoolConnection(model.AlgoType);

                model.FixedDiffSummary     = poolconnection.FixedDiffSummary;
                model.VarDiffHighSummary   = poolconnection.VarDiffHighSummary;
                model.VarDiffLowSummary    = poolconnection.VarDiffLowSummary;
                model.VarDiffMediumSummary = poolconnection.VarDiffMediumSummary;
                return(View("UpdateWorkerModal", model));
            }

            model.TargetDifficulty = PoolExtensions.OptionToTargetDifficulty(model.DifficultyOption, model.TargetDifficulty);
            var result = await PoolWorkerWriter.AdminUpdateWorker(model);

            if (!ModelState.IsWriterResultValid(result))
            {
                return(View("UpdateWorkerModal", model));
            }

            return(CloseModal(result));
        }