public async Task <CardSectionDataTaskResult <CardSectionMessage> > Process(CardSectionMessage cardSectionData)
        {
            var cardSectionDataTaskResult = new CardSectionDataTaskResult <CardSectionMessage>
            {
                CardSectionData = cardSectionData
            };

            var card = await _cardService.CardByName(cardSectionData.Name);

            if (card != null)
            {
                await _cardTipService.DeleteByCardId(card.Id);

                var newTipSectionList = new List <TipSection>();

                foreach (var cardSection in cardSectionData.CardSections)
                {
                    var newTipSection = new TipSection
                    {
                        CardId  = card.Id,
                        Name    = cardSection.Name,
                        Created = DateTime.UtcNow,
                        Updated = DateTime.UtcNow
                    };

                    foreach (var tip in cardSection.ContentList)
                    {
                        newTipSection.Tip.Add(new Tip
                        {
                            TipSection = newTipSection,
                            Text       = tip,
                            Created    = DateTime.UtcNow,
                            Updated    = DateTime.UtcNow
                        });
                    }

                    newTipSectionList.Add(newTipSection);
                }

                if (newTipSectionList.Any())
                {
                    await _cardTipService.Update(newTipSectionList);
                }
            }
            else
            {
                cardSectionDataTaskResult.Errors.Add($"Card Tips: card '{cardSectionData.Name}' not found.");
            }


            return(cardSectionDataTaskResult);
        }
예제 #2
0
        public async Task <CardSectionDataTaskResult <CardSectionMessage> > Process(CardSectionMessage cardSectionData)
        {
            var cardSectionDataTaskResult = new CardSectionDataTaskResult <CardSectionMessage>
            {
                CardSectionData = cardSectionData
            };

            var card = await _cardService.CardByName(cardSectionData.Name);

            if (card != null)
            {
                await _cardRulingService.DeleteByCardId(card.Id);

                var rulingSections = new List <RulingSection>();

                foreach (var cardSection in cardSectionData.CardSections)
                {
                    var rulingSection = new RulingSection
                    {
                        CardId  = card.Id,
                        Name    = cardSection.Name,
                        Created = DateTime.UtcNow,
                        Updated = DateTime.UtcNow
                    };

                    foreach (var ruling in cardSection.ContentList)
                    {
                        rulingSection.Ruling.Add(new Ruling
                        {
                            RulingSection = rulingSection,
                            Text          = ruling,
                            Created       = DateTime.UtcNow,
                            Updated       = DateTime.UtcNow
                        });
                    }

                    rulingSections.Add(rulingSection);
                }

                if (rulingSections.Any())
                {
                    await _cardRulingService.Update(rulingSections);
                }
            }
            else
            {
                cardSectionDataTaskResult.Errors.Add($"Card Rulings: card '{cardSectionData.Name}' not found.");
            }


            return(cardSectionDataTaskResult);
        }