Ejemplo n.º 1
0
        public async Task <ActionResult <ApiResultViewModel <ShopItemViewModel> > > GetById([FromRoute] string id,
                                                                                            CancellationToken cancellationToken)
        {
            var shopItem = await _shopItemManager.GetByIdAsyncThrowNotFoundIfNotExists(id, cancellationToken);

            return(OkData(ShopItemViewModel.Map(shopItem)));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <ApiResultViewModel <ShopItemViewModel> > > Create([FromBody] ShopItemInputModel inputModel,
                                                                                           CancellationToken cancellationToken)
        {
            var shopItem = new ShopItem
            {
                Title            = inputModel.Title,
                Price            = inputModel.Price,
                PriceTypeId      = inputModel.PriceTypeId.ToInt(),
                TypeId           = inputModel.TypeId.ToInt(),
                StatusId         = inputModel.StatusId.ToInt(),
                ImageFileId      = inputModel.ImageFileId,
                UnlockLevel      = inputModel.UnlockLevel,
                UnlockSky        = inputModel.UnlockSky,
                AvatarCategoryId = inputModel.AvatarCategoryId?.ToInt(),
                AvatarTypeId     = inputModel.AvatarTypeId?.ToInt(),
                DefaultAvatar    = inputModel.DefaultAvatar,
                Description      = inputModel.Description
            };

            shopItem = await _shopItemManager.SaveAsync(shopItem, cancellationToken);

            return(OkData(ShopItemViewModel.Map(shopItem)));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <ApiResultViewModel <ShopItemViewModel> > > Update([FromRoute] string id, [FromBody] ShopItemInputModel inputModel,
                                                                                           CancellationToken cancellationToken)
        {
            //TODO: what if somebody has bought a shop item and we update it?

            var shopItem = await _shopItemManager.GetByIdAsyncThrowNotFoundIfNotExists(id, cancellationToken);

            shopItem.Title            = inputModel.Title;
            shopItem.Price            = inputModel.Price;
            shopItem.PriceTypeId      = inputModel.PriceTypeId.ToInt();
            shopItem.TypeId           = inputModel.TypeId.ToInt();
            shopItem.StatusId         = inputModel.StatusId.ToInt();
            shopItem.ImageFileId      = inputModel.ImageFileId;
            shopItem.UnlockLevel      = inputModel.UnlockLevel;
            shopItem.UnlockSky        = inputModel.UnlockSky;
            shopItem.AvatarCategoryId = inputModel.AvatarCategoryId?.ToInt();
            shopItem.AvatarTypeId     = inputModel.AvatarTypeId?.ToInt();
            shopItem.DefaultAvatar    = inputModel.DefaultAvatar;
            shopItem.Description      = inputModel.Description;

            shopItem = await _shopItemManager.SaveAsync(shopItem, cancellationToken);

            return(OkData(ShopItemViewModel.Map(shopItem)));
        }