public async Task <IWriterResult> UpdateWorker(string userId, PoolWorkerUpdateModel model) { var currentUserId = new Guid(userId); using (var context = PoolDataContextFactory.CreateContext()) { var worker = await context.Worker.Where(w => w.Id == model.Id && w.UserId == currentUserId) .FirstOrDefaultNoLockAsync() .ConfigureAwait(false); if (worker == null) { return(new WriterResult(false, "Worker '{0}' not found.", model.Name)); } var profitPool = string.Empty; if (model.IsAutoSwitch) { worker.TargetPool = await context.Statistics .Where( x => x.Pool.IsEnabled && x.Pool.AlgoType == model.AlgoType && (x.Pool.Status == Enums.PoolStatus.OK || x.Pool.Status == Enums.PoolStatus.Expiring)) .OrderByDescending(x => x.Profitability) .Select(x => x.Pool.Symbol) .FirstOrDefaultNoLockAsync().ConfigureAwait(false); } worker.Password = model.Password; worker.IsAutoSwitch = model.IsAutoSwitch; worker.TargetDifficulty = model.TargetDifficulty; await context.SaveChangesAsync().ConfigureAwait(false); await CacheService.InvalidateAsync(CacheKey.PoolWorkers(userId)).ConfigureAwait(false); return(new WriterResult(true, $"Successfully updated worker '{worker.Name}'")); } }
public async Task <ActionResult> UpdateWorker(PoolWorkerUpdateModel 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.UpdateWorker(User.Identity.GetUserId(), model); if (!ModelState.IsWriterResultValid(result)) { return(View("UpdateWorkerModal", model)); } return(CloseModal(result)); }