Exemplo n.º 1
0
 public void UpdateMake(Guid makeId, string makeName)
 {
     makeName = makeName.Trim();
     LockHelper.LockAction(
         _makeLock,
         () => DataProvider.Makes.Any(x => x.Key == makeId),
         () =>
     {
         DataProvider.Makes[makeId].Name = makeName;
     },
         () => throw new ResourceNotFoundException(nameof(makeId), makeId.ToString()));
 }
Exemplo n.º 2
0
 public void UpdateModel(Guid modelId, string modelName)
 {
     modelName = modelName.Trim();
     LockHelper.LockAction(
         _modelLock,
         () => DataProvider.Models.Any(x => x.Key == modelId),
         () =>
     {
         DataProvider.Models[modelId].Name = modelName;
     },
         () => throw new ResourceNotFoundException(nameof(modelId), modelId.ToString()));
 }
Exemplo n.º 3
0
 public MakeOutputModel AddMake(string makeName)
 {
     makeName = makeName.Trim();
     return(LockHelper.LockAction <MakeOutputModel>(
                _makeLock,
                // De-duplicate the model with the same makeName...
                () => !DataProvider.Makes.Any(x => string.Equals(x.Value.Name, makeName, StringComparison.InvariantCultureIgnoreCase)),
                () =>
     {
         var newMake = new MakeInputModel(makeName);
         DataProvider.Makes.TryAdd(newMake.Id, newMake);
         return _mapper.Map <MakeOutputModel>(newMake);
     },
                () => throw new ResourceConflictException(nameof(MakeInputModel.Name), makeName)));
 }
Exemplo n.º 4
0
 public DealerModel Add(string dealerName)
 {
     dealerName = dealerName.Trim();
     return(LockHelper.LockAction <DealerModel>(
                _lock,
                () => !DataProvider.Dealers.Any(x => x.Value.Name == dealerName),
                () =>
     {
         var dealer = new DealerModel(dealerName);
         DataProvider.Dealers.TryAdd(dealer.Id, dealer);
         return dealer;
     },
                () => throw new ResourceConflictException(nameof(dealerName), dealerName)
                ));
 }
Exemplo n.º 5
0
        public ModelOutputModel AddModel(Guid makeId, string modelName)
        {
            modelName = modelName.Trim();
            // The make with the id should exist in the make list
            if (!DataProvider.Makes.Any(x => x.Key == makeId))
            {
                throw new ResourceNotFoundException(nameof(makeId), makeId.ToString());
            }

            return(LockHelper.LockAction <ModelOutputModel>(
                       _modelLock,
                       // De-duplicate the model with the same name & makeId...
                       () => !DataProvider.Models.Any(x => x.Value.MakeId == makeId &&
                                                      String.Equals(x.Value.Name, modelName, StringComparison.InvariantCultureIgnoreCase)),
                       () =>
            {
                var model = new ModelInputModel(makeId, modelName);
                DataProvider.Models.TryAdd(model.Id, model);
                return _mapper.Map <ModelOutputModel>(model);
            },
                       () => throw new ResourceConflictException(nameof(modelName), modelName)));
        }