Example #1
0
        public IHttpActionResult PutAsset(Asset asset)
        {
            using (var scope = new TransactionScope())
            {
                var job = _db.Jobs.GetById(asset.JobId);
                if (job == null)
                    return NotFound();

                if (job.LockedBy != null && !User.Identity.Name.Equals(job.LockedBy))
                    return BadRequest("Job locked");

                _db.Assets.Update(asset);

                try
                {
                    _db.AcceptChanges();
                    scope.Complete();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Exists(asset))
                    {
                        return NotFound();
                    }
                    return BadRequest("Attempt to update with stale data.");
                }
            }
            return Ok(asset);
        }
Example #2
0
 private bool Exists(Asset asset)
 {
     return _db
         .Assets
         .GetAll()
         .Where(_ => _.Id == asset.Id)
         .Any();
 }
Example #3
0
 private ChangeItem<Asset> ModifyAsset(Asset asset)
 {
     var choice = s_rng.NextDouble();
     ChangeItem<Asset> change;
     if (s_rng.NextDouble() < s_chanceDelete)
     {
         change = new ChangeItem<Asset>(ChangeAction.Delete, asset, null);
     }
     else
     {
         change = new ChangeItem<Asset>(ChangeAction.Update, asset, Dirty(asset));
     }
     return change;
 }
Example #4
0
        private static Asset Dirty(Asset asset)
        {
            asset.MaximumAndMinimumDecay = GetNewValuePercent(asset.MaximumAndMinimumDecay, 29);
            asset.MaxMinDecayWithStepAndTol = GetNewValuePercent(asset.MaxMinDecayWithStepAndTol, 29);
            asset.MinimumDecay = GetNewValuePercent(asset.MinimumDecay, 19);
            asset.MonotonicTolerance = GetNewValuePercent(asset.MonotonicTolerance, 9);
            asset.PercentTolerance = GetNewValuePercent(asset.PercentTolerance, 9);
            asset.StaticTolerance = GetNewValuePercent(asset.StaticTolerance, 19);

            return asset;
        }