Exemplo n.º 1
0
        public IHttpActionResult Post([FromBody] CreatePassModel command)
        {
            // Check empty name
            if (string.IsNullOrWhiteSpace(command.Name))
            {
                return(this.Error().InvalidParameters("Pass name must be set"));
            }

            if (!ModelState.IsValid)
            {
                return(this.Error().InvalidParameters("Invalid pass parameters"));
            }

            // Check that pass doesn't exist
            Pass pass = _passRepository.Get(command.Id);

            if (pass != null)
            {
                return(this.Error().InvalidParameters("Pass already exists"));
            }

            // Check that pass with such name doesn't exist
            pass = _passRepository.FindByName(command.Name, command.IsLibraried);
            if (pass != null)
            {
                return(this.Error().InvalidParameters("Pass with such name already exists"));
            }

            if (_passInspectorService.InspectPassSalesAreaPriorities(
                    command.PassSalesAreaPriorities,
                    out string errorMessage))
            {
                return(this.Error().InvalidParameters(errorMessage));
            }

            List <string> breakExclusionsErrorMessages = new List <string>();

            if (!BreakExclusionsValidations.DateTimeRangeIsValid(command.BreakExclusions, _salesAreaRepository.GetAll(), out breakExclusionsErrorMessages))
            {
                return(this.Error().InvalidParameters(breakExclusionsErrorMessages));
            }

            pass = _mapper.Map <Pass>(command);
            IdUpdater.SetIds(pass, _identityGeneratorResolver);

            // Validate
            ValidateForSave(pass);

            // Save
            _passRepository.Add(pass);
            _passRepository.SaveChanges();   // Do not remove this, need to persist changes now so that we can return PassModel

            return(Ok(Mappings.MapToPassModel(pass, _passRepository, _mapper)));
        }
Exemplo 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);
            }
        }
Exemplo n.º 3
0
 public void AddPass(Pass Pass)
 {
     _iRespository.Add(Pass);
 }
Exemplo n.º 4
0
        public async Task AddPass(Pass pass)
        {
            await _repository.Add(pass);

            await _unit.Complete();
        }
Exemplo n.º 5
0
 public Pass Add(Pass model)
 {
     _repository.Add(model);
     return(model);
 }