Exemple #1
0
        public async Task DeleteAsync(string regulationId)
        {
            IRegulation regulation = await _regulationRepository.GetAsync(regulationId);

            if (regulation == null)
            {
                throw new ServiceException("Regulation not found.");
            }

            IEnumerable <IClientRegulation> clientAvailableRegulations =
                await _clientRegulationRepository.GetByRegulationIdAsync(regulationId);

            if (clientAvailableRegulations.Any())
            {
                throw new ServiceException("Can not delete regulation associated with one or more clients.");
            }

            IEnumerable <IWelcomeRegulationRule> welcomeRegulationRules =
                await _welcomeRegulationRuleRepository.GetByRegulationIdAsync(regulationId);

            if (welcomeRegulationRules.Any())
            {
                throw new ServiceException("Can not delete regulation associated with one or more welcome rules.");
            }

            await _regulationRepository.DeleteAsync(regulationId);
        }
Exemple #2
0
        public async Task AddAsync(IRegulation regulation)
        {
            if (await _regulationRepository.GetAsync(regulation.Id) != null)
            {
                throw new ServiceException("Regulation already exists.");
            }

            await _regulationRepository.AddAsync(regulation);
        }
Exemple #3
0
        public async Task <IEnumerable <IClientRegulation> > GetByRegulationIdAsync(string regulationId)
        {
            IRegulation result = await _regulationRepository.GetAsync(regulationId);

            if (result == null)
            {
                throw new ServiceException("Regulation not found.");
            }

            return(await _clientRegulationRepository.GetByRegulationIdAsync(regulationId));
        }
Exemple #4
0
        public async Task AddAsync(IWelcomeRegulationRule welcomeRegulationRule)
        {
            IRegulation result = await _regulationRepository.GetAsync(welcomeRegulationRule.RegulationId);

            if (result == null)
            {
                throw new ServiceException("Regulation not found.");
            }

            await _welcomeRegulationRuleRepository.AddAsync(welcomeRegulationRule);
        }
 public RegulationAdminController()
 {
     try
     {
         iRegulation = new RegulationRepository();
     }
     catch (Exception ex)
     {
         Utility.WriteLog("RegulationAdminController (Admin)", null, "Error while initialize repository.", ex.ToString());
     }
 }
Exemple #6
0
        public async Task <IRegulation> GetAsync(string regulationId)
        {
            IRegulation regulation = await _regulationRepository.GetAsync(regulationId);

            if (regulation == null)
            {
                throw new ServiceException("Regulation not found.");
            }

            return(regulation);
        }
 public void EditRegulation(IRegulation aRegulation)
 {
     using (var session = NHibernateHelper.OpenSession()) {
         using (var transaction = session.BeginTransaction()) {
             var entity = session.Get<RegulationEntity>(aRegulation.GetId());
             entity.DimentionId = aRegulation.GetDimentionId();
             entity.StandartSizeId = aRegulation.GetStandartSizeId();
             entity.MaxValue = aRegulation.GetMaxValue();
             entity.MinValue = aRegulation.GetMinValue();
             session.Update(entity);
             transaction.Commit();
         }
     }
 }
        public int CreateRegulation(IRegulation aRegulation)
        {
            using (var session = NHibernateHelper.OpenSession()) {
                var entity = new RegulationEntity {
                    DimentionId = aRegulation.GetDimentionId(),
                    StandartSizeId = aRegulation.GetStandartSizeId(),
                    MaxValue = aRegulation.GetMaxValue(),
                    MinValue = aRegulation.GetMinValue()
                };

                using (var transaction = session.BeginTransaction()) {
                    session.Save(entity);
                    transaction.Commit();
                }

                return entity.Id;
            }
        }
Exemple #9
0
        public async Task AddAsync(IClientRegulation clientRegulation)
        {
            IRegulation result = await _regulationRepository.GetAsync(clientRegulation.RegulationId);

            if (result == null)
            {
                throw new ServiceException("Regulation not found.");
            }

            if (await _clientRegulationRepository.GetAsync(clientRegulation.ClientId, clientRegulation.RegulationId) != null)
            {
                throw new ServiceException("Client regulation already exists.");
            }

            await _clientRegulationRepository.AddAsync(clientRegulation);

            await PublishOnChangedAsync(clientRegulation.ClientId);

            _log.Info(nameof(AddAsync), $"Regulation '{clientRegulation.RegulationId}' added for client.", clientRegulation.ClientId);
        }
Exemple #10
0
 public Task AddAsync(IRegulation regulation)
 {
     return(_tableStorage.InsertThrowConflict(Create(regulation.Id)));
 }