예제 #1
0
 protected override void OnActionExecuted(ActionExecutedContext filterContext)
 {
     if (filterContext.RouteData.Values["action"].Equals("create") || filterContext.RouteData.Values["action"].Equals("edit"))
     {
         var all = _attributeService.GetAll();
         ViewBag.Attributes = all;
     }
 }
예제 #2
0
        public async Task <IActionResult> Get()
        {
            var result = await _attributeServices.GetAll();

            if (result == null)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
        public async Task <IActionResult> Get()
        {
            const string loggerHeader = "Attributes -";

            _logService.Info($"{loggerHeader} Start");
            var result = new ApiJsonResult();

            try
            {
                result.Data = await _AttributeService.GetAll();
            }
            catch (Exception ex)
            {
                _logService.Error($"{loggerHeader} Throw error {ex.Message}");
                result.Code    = CodeModel.Fail;
                result.Message = ex.Message;
            }

            return(Ok(result));
        }
        public async Task <AddCardCommand> MapToAddCommand(YugiohCard yugiohCard)
        {
            ICollection <Category> categories = await _categoryService.GetAll();

            ICollection <SubCategory> subCategories = await _subCategoryService.GetAll();

            var command = new AddCardCommand();

            command.CardType    = yugiohCard.CardType;
            command.CardNumber  = yugiohCard.CardNumber;
            command.Name        = yugiohCard.Name;
            command.Description = yugiohCard.Description;

            if (yugiohCard.ImageUrl != null)
            {
                command.ImageUrl = new Uri(yugiohCard.ImageUrl);
            }


            if (command.CardType.Equals(YgoCardType.Spell.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                command.SubCategoryIds = new List <int>
                {
                    SubCategoryId(categories, subCategories, YgoCardType.Spell, yugiohCard.Property)
                };
            }
            else if (command.CardType.Equals(YgoCardType.Trap.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                command.SubCategoryIds = new List <int>
                {
                    SubCategoryId(categories, subCategories, YgoCardType.Trap, yugiohCard.Property)
                };
            }
            else
            {
                ICollection <Type> types = await _typeService.GetAll();

                ICollection <Attribute> attributes = await _attributeService.GetAll();

                ICollection <LinkArrow> linkArrows = await _linkArrowService.GetAll();

                var monsterCategory      = categories.Single(c => c.Name.Equals(YgoCardType.Monster.ToString(), StringComparison.OrdinalIgnoreCase));
                var monsterSubCategories = subCategories.Select(sc => sc).Where(sc => sc.CategoryId == monsterCategory.Id);

                command.AttributeId = MonsterAttributeId(yugiohCard, attributes);

                command.SubCategoryIds = MonsterSubCategoryIds(yugiohCard, monsterSubCategories);
                command.TypeIds        = MonsterTypeIds(yugiohCard, types);

                if (yugiohCard.LinkArrows != null)
                {
                    command.LinkArrowIds = MonsterLinkArrowIds(yugiohCard, linkArrows);
                }


                if (yugiohCard.Level.HasValue)
                {
                    command.CardLevel = yugiohCard.Level;
                }

                if (yugiohCard.Rank.HasValue)
                {
                    command.CardRank = yugiohCard.Rank;
                }

                if (!string.IsNullOrWhiteSpace(yugiohCard.AtkDef))
                {
                    var atk = Atk(yugiohCard);
                    var def = DefOrLink(yugiohCard);

                    int.TryParse(atk, out var cardAtk);
                    int.TryParse(def, out var cardDef);

                    command.Atk = cardAtk;
                    command.Def = cardDef;
                }

                if (!string.IsNullOrWhiteSpace(yugiohCard.AtkLink))
                {
                    var atk = Atk(yugiohCard);

                    int.TryParse(atk, out var cardAtk);

                    command.Atk = cardAtk;
                }
            }

            return(command);
        }