コード例 #1
0
        public async Task <TagsCommandResponse> Handle(CreateTagsCommand request, CancellationToken cancellationToken)
        {
            TagsCommandResponse response = new TagsCommandResponse()
            {
                IsSuccessful = false
            };

            TaxTags _taxTag = new TaxTags();

            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                _taxTag.IsPublished = true;
                _taxTag.CreatedBy   = "";
                _taxTag.CreatedDate = DateTime.Now;
                _taxTag.UpdatedBy   = "";
                _taxTag.UpdatedDate = DateTime.Now;
                _taxTag.ParentTagId = null;
                if (request.TagType == "Tag")
                {
                    _taxTag.ParentTagId = request.TagGroup;
                    foreach (var country in request.RelatedCountyIds)
                    {
                        TaxTagRelatedCountries objRelatedCountries = new TaxTagRelatedCountries();
                        objRelatedCountries.CountryId = country;
                        _taxTag.TaxTagRelatedCountries.Add(objRelatedCountries);
                    }
                }
                foreach (var langName in request.LanguageName)
                {
                    var taxTagsContent = new TaxTagContents();
                    taxTagsContent.DisplayName = langName.Name.Trim();
                    taxTagsContent.LanguageId  = langName.LanguageId;
                    _taxTag.TaxTagContents.Add(taxTagsContent);
                }
                _taxTagsRepository.Add(_taxTag);
                await _taxTagsRepository.UnitOfWork
                .SaveEntitiesAsync();

                response.IsSuccessful = true;
                scope.Complete();
            }
            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                foreach (var content in _taxTag.TaxTagContents)
                {
                    var eventSourcing = new TagGroupCommandEvent()
                    {
                        EventType         = ServiceBusEventType.Create,
                        Discriminator     = Constants.TaxTagsDiscriminator,
                        TagId             = _taxTag.TaxTagId,
                        ParentTagId       = _taxTag.ParentTagId,
                        IsPublished       = _taxTag.IsPublished,
                        CreatedBy         = _taxTag.CreatedBy,
                        CreatedDate       = _taxTag.CreatedDate,
                        UpdatedBy         = _taxTag.UpdatedBy,
                        UpdatedDate       = _taxTag.UpdatedDate,
                        RelatedCountryIds = (from rc in _taxTag.TaxTagRelatedCountries where rc != null select rc.CountryId).ToList(),
                        TagContentId      = content.TaxTagContentId,
                        LanguageId        = content.LanguageId,
                        DisplayName       = content.DisplayName,
                        PartitionKey      = ""
                    };
                    await _Eventcontext.PublishThroughEventBusAsync(eventSourcing);
                }
                scope.Complete();
            }
            return(response);
        }
コード例 #2
0
 public void DeletetagGroup(TaxTags tagGroup)
 {
     _context.TaxTags.Remove(tagGroup);
 }
コード例 #3
0
        public TaxTags getTaxTagsById(int TaxTagsId)
        {
            TaxTags objTaxTags = _context.TaxTags.Where(s => s.TaxTagId == TaxTagsId).FirstOrDefault();

            return(objTaxTags);
        }
コード例 #4
0
 public TaxTags Add(TaxTags _taxTags)
 {
     return(_context.TaxTags.Add(_taxTags).Entity);
 }