Esempio n. 1
0
        public IHttpActionResult Get(int id)
        {
            var item = _passRepository.Get(id);

            if (item is null)
            {
                return(NotFound());
            }
            return(Ok(Mappings.MapToPassModel(item, _passRepository, _mapper)));
        }
Esempio n. 2
0
        /// <summary>
        /// Updates Pass repository for passes
        /// </summary>
        /// <param name="scenario"></param>
        /// <param name="command"></param>
        /// <param name="deletedPassIds"></param>
        private void UpdatePassRepository(Scenario scenario, CreateScenarioModel command, List <int> deletedPassIds)
        {
            List <Pass> updatedPasses = new List <Pass>();
            List <Pass> newPasses     = new List <Pass>();

            // Get changes for Pass repository
            for (int passIndex = 0; passIndex < scenario.Passes.Count; passIndex++)
            {
                PassReference passReference = scenario.Passes[passIndex];
                PassModel     passModel     = command.Passes[passIndex];
                Pass          pass          = passReference.Id == 0 ? null : _passRepository.Get(passReference.Id);
                if (pass == null)   // New pass
                {
                    pass    = _mapper.Map <Pass>(passModel);
                    pass.Id = passReference.Id;     // Set in previous call to IdUpdater.SetIds
                    Pass.ValidateForSave(pass);
                    newPasses.Add(pass);
                }
                else    // Update pass
                {
                    Mappings.ApplyToPass(pass, passModel, _mapper);
                    Pass.ValidateForSave(pass);
                    updatedPasses.Add(pass);
                }
            }

            // Add/update
            updatedPasses.ForEach(currentPass => _passRepository.Update(currentPass));
            newPasses.ForEach(currentPass => _passRepository.Add(currentPass));

            // Delete passes
            if (deletedPassIds != null && deletedPassIds.Any())
            {
                _passRepository.Remove(deletedPassIds);
            }
        }
Esempio n. 3
0
 public Pass GetPass(Expression <Func <Pass, bool> > where)
 {
     return(_iRespository.Get(where));
 }
Esempio n. 4
0
 public async Task <IEnumerable <Pass> > GetPasses()
 {
     return(await _repository.Get());
 }