예제 #1
0
        /// <summary>
        /// 父类迭代子类返回实体
        /// </summary>
        /// <param name="roots"></param>
        /// <param name="all"></param>
        /// <param name="models"></param>
        /// <param name="currentModel"></param>
        public static void Recursion(IEnumerable <CardType> roots, List <CardType> all, ICollection <CardTypeModel> models,
                                     CardTypeModel currentModel = null)
        {
            foreach (var root in roots)
            {
                var model = Mapper.Map <CardType, CardTypeModel>(root);

                if (currentModel != null && currentModel.Id == root.Parent.Id)
                {
                    if (currentModel.SubCardTypeModels == null)
                    {
                        currentModel.SubCardTypeModels = new List <CardTypeModel>();
                    }
                    currentModel.SubCardTypeModels.Add(model);
                }
                else
                {
                    models.Add(model);
                }
                var subs = all.Where(n => n.Parent == root).ToArray();
                if (subs.Any())
                {
                    Recursion(subs, all, models, model);
                }
            }
        }
예제 #2
0
        public CardTypeModel CreateCardType(string name, Guid guid, TemplateInfoModel templateInfo)
        {
            var cardType = Context.CardTypes.FindByGuid(guid);

            if (cardType == null)
            {
                var utcNow = DateTime.UtcNow;
                cardType = new CardTypeModel
                {
                    Name = name,
                    Guid = guid,

                    LastModifiedTime = utcNow,
                    CreateTime       = utcNow,
                    Creator          = ServiceUser,
                    LastModifiedBy   = ServiceUser,

                    TemplateInfo = templateInfo
                };

                Context.CardTypes.Add(cardType);
                Context.SaveChanges();
            }
            return(cardType);
        }
예제 #3
0
        public JsonResult SaveCardType(CardTypeModel cardType)
        {
            var dbCardType = _dataProvider.GetCardType(cardType.Id) ?? new CardType();
            var entity     = _cardTypeMapper.MapToEntity(cardType, ref dbCardType);

            _dataProvider.SaveCardType(entity);
            return(Json(entity.Id));
        }
예제 #4
0
 public static void Patch(this CardTypeModel cardTypeModel, CardType cardType, TemplateInfoModel templateInfoModel, UserModel user)
 {
     if (cardTypeModel == null)
     {
         return;
     }
     cardTypeModel.Name         = cardType.Name;
     cardTypeModel.TemplateInfo = templateInfoModel;
     cardTypeModel.PatchBase(user);
 }
예제 #5
0
        public static void Patch(this CardModel cardModel, Card card,
                                 SerieModel serieModel, FactionModel factionModel, CardTypeModel cardTypeModel, StatusModel statusModel, RuleSetModel ruleSetModel, LicenseModel artworkLicense, UserModel user)
        {
            if (cardModel == null)
            {
                return;
            }
            if (card == null)
            {
                return;
            }
            cardModel.Name            = card.Name;
            cardModel.FirstName       = card.FirstName;
            cardModel.LastName        = card.LastName;
            cardModel.Artist          = card.Artist;
            cardModel.ArtworkLicensor = card.ArtworkLicensor;
            cardModel.RuleText        = card.RuleText;
            cardModel.FlavorText      = card.FlavorText;
            cardModel.SubType         = card.SubType;
            cardModel.Cost            = card.Cost;
            cardModel.Loyalty         = card.Loyalty;
            cardModel.Attack          = card.Attack;
            cardModel.Defense         = card.Defense;
            cardModel.Info            = card.Info;
            cardModel.MarkdownText    = card.MarkdownText;
            cardModel.LanguageCode    = card.Language?.LanguageCode ?? "en";


            if (serieModel != null)
            {
                cardModel.Serie = serieModel;
            }
            if (factionModel != null)
            {
                cardModel.Faction = factionModel;
            }
            if (cardTypeModel != null)
            {
                cardModel.Type = cardTypeModel;
            }
            if (statusModel != null)
            {
                cardModel.Status = statusModel;
            }
            if (ruleSetModel != null)
            {
                cardModel.RuleSet = ruleSetModel;
            }
            if (artworkLicense != null)
            {
                cardModel.ArtworkLicense = artworkLicense;
            }

            cardModel.PatchBase(user);
        }
예제 #6
0
        public object Get(Guid id)
        {
            Mapper.Reset();
            Mapper.CreateMap <CardDemo, CardDemoModel>();
            Mapper.CreateMap <CardType, CardTypeModel>().ForMember(n => n.CardDemoModels, opt => opt.MapFrom(src => src.CardDemos));
            var all    = _cardTypeService.GetCardTypes().ToList();
            var root   = all.FirstOrDefault(n => n.Id == id);
            var result = new CardTypeModel();

            Recursion(root, all, result);
            return(result);
        }
예제 #7
0
        /// <summary>
        /// 父类迭代子类返回实体
        /// </summary>
        /// <param name="root"></param>
        /// <param name="all"></param>
        /// <param name="currentModel"></param>
        public static void Recursion(CardType root, List <CardType> all, CardTypeModel currentModel = null)
        {
            currentModel = Mapper.Map <CardType, CardTypeModel>(root);
            var subs = all.Where(n => n.Parent.Id == currentModel.Id);

            foreach (var cardType in subs)
            {
                if (currentModel.SubCardTypeModels == null)
                {
                    currentModel.SubCardTypeModels = new List <CardTypeModel>();
                }
                currentModel.SubCardTypeModels.Add(Mapper.Map <CardType, CardTypeModel>(cardType));
                Recursion(cardType, all, currentModel);
            }
        }
예제 #8
0
 public static void Patch(this CardModel cardModel, Card card,
                          SerieModel serieModel, FactionModel factionModel, CardTypeModel cardTypeModel, StatusModel statusModel, RuleSetModel ruleSetModel, UserModel user)
 {
     if (cardModel == null)
     {
         return;
     }
     if (card == null)
     {
         return;
     }
     cardModel.Name       = card.Name;
     cardModel.FirstName  = card.FirstName;
     cardModel.LastName   = card.LastName;
     cardModel.Artist     = card.Artist;
     cardModel.RuleText   = card.RuleText;
     cardModel.FlavorText = card.FlavorText;
     cardModel.SubType    = card.SubType;
     cardModel.Cost       = card.Cost;
     cardModel.Loyalty    = card.Loyalty;
     cardModel.Attack     = card.Attack;
     cardModel.Defense    = card.Defense;
     cardModel.Info       = card.Info;
     cardModel.LayoutText = card.LayoutText;
     if (serieModel != null)
     {
         cardModel.Serie = serieModel;
     }
     if (factionModel != null)
     {
         cardModel.Faction = factionModel;
     }
     if (cardTypeModel != null)
     {
         cardModel.Type = cardTypeModel;
     }
     if (statusModel != null)
     {
         cardModel.Status = statusModel;
     }
     if (ruleSetModel != null)
     {
         cardModel.RuleSet = ruleSetModel;
     }
     cardModel.Patch(user);
 }
예제 #9
0
        public static CardType FromDal(this CardTypeModel cardTypeModel, bool includeTemplateInfo = false)
        {
            if (cardTypeModel == null)
            {
                return(null);
            }
            var result = new CardType()
            {
                Id   = cardTypeModel.CardTypeId,
                Name = cardTypeModel.Name
            };

            if (includeTemplateInfo)
            {
                result.TemplateInfo = cardTypeModel.TemplateInfo.FromDal();
            }
            return(result.SyncBase(cardTypeModel));
        }