public void Add(T entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity), "Entity cannot be null");
            }

            var entityId = entity.getId().ToString();

            lock (repositoryLocker)
            {
                if (_cachedDictionary.ContainsKey(entity.getId()) ||
                    (_loadingMode == RepositoryMode.Lazy && _repositoryProvider.Get(entityId) != null))
                {
                    throw new InvalidOperationException("entity with the same id already exists");
                }

                try
                {
                    var data = _converter.FromEntity(entity);

                    _repositoryProvider.Add(data);
                    _cachedDictionary.Add(entity.getId(), entity);
                }
                catch (Exception)
                {
                    throw new Exception("cant add a new entity");
                }
            }

            onEntityAction(entity.getId(), EntityActions.Add);
        }
 public void Add(Models.Repository item)
 {
     try
     {
         inner.Add(item);
     }
     finally
     {
         Kooboo.CMS.Caching.CacheManagerFactory.DefaultCacheManager.ClearGlobalObjectCache();
     }
 }
Exemple #3
0
        private void _Add(T entity)
        {
            CheckInitialization();

            if (CheckEntityExist(entity))
            {
                throw new ArgumentException("Entity already exists, use update");
            }

            var entry = _entityTranslator.MapEntity(entity);

            if (_repositoryProvider.Add(entry))
            {
                _entityCache.Add(entity.Id, entity);
                OnAdd(entity.Id);
            }
        }
Exemple #4
0
        public void Add(Provider provider)
        {
            _repositoryProvider.Add(provider);

            if (provider.Addresses.Any())
            {
                foreach (var address in provider.Addresses)
                {
                    address.SetProvider(provider.Id);
                    _serviceAddress.Add(address);
                }
            }

            if (provider.Addresses.Any())
            {
                foreach (var contact in provider.Contacts)
                {
                    contact.SetProvider(provider.Id);
                    _serviceContact.Add(contact);
                }
            }
        }
Exemple #5
0
 public void Add(Repository item)
 {
     inner.Add(item);
 }
Exemple #6
0
 public void Add(Models.Repository item)
 {
     inner.Add(item);
 }
        protected async Task <Campaign> ProcessCampaign(Guid competitionKey, DateTime matchDate)
        {
            var campaign = await Provider.FindCampaignAsync(competitionKey, matchDate);

            if (campaign != null)
            {
                return(campaign);
            }

            var competitionViewModel = await Provider.GetCompetition(competitionKey, matchDate);

            if (competitionViewModel == null)
            {
                return(null);
            }

            var startDate = Date.LowDate;
            var endDate   = Date.HighDate;

            if (!competitionViewModel.GetCampaignDates(matchDate, ref startDate, ref endDate))
            {
                return(null);
            }

            var newCampaign = Campaign.CreateNew(competitionViewModel.HeaderKey, startDate, endDate);

            campaign = newCampaign;

            Provider.Add(newCampaign);
            Provider.SaveChanges();

            return(campaign);
        }