Esempio n. 1
0
        public async Task <IActionResult> Create([FromForm] ItemCreateRequest request)
        {
            _logger.LogInformation($"Creating a new item with SKU: {request.SKU}");

            Category category = await _categoryRepository.FindByID(request.CategoryID);

            if (category == null)
            {
                _logger.LogInformation($"No category found with id {request.CategoryID}");
                return(StatusCode((int)HttpStatusCode.NotFound,
                                  new ErrorResponse(ErrorReasons.NotFound, "Category was not found")));
            }

            if (request.SubcategoryID.HasValue)
            {
                SubCategory subCategory = await _categoryRepository.FindSubCategoryByID(request.SubcategoryID.Value);

                if (subCategory == null)
                {
                    _logger.LogInformation($"No subcategory found with id {request.SubcategoryID.Value}");
                    return(StatusCode((int)HttpStatusCode.NotFound,
                                      new ErrorResponse(ErrorReasons.NotFound, "Subcategory was not found")));
                }
            }

            List <string> pictureURLs = BuildPictureUrlList(request.PictureURLs, request.PictureFiles);

            using (var transaction = await _attributeRepository.Context.Database.BeginTransactionAsync())
            {
                await CreateNewAttributes(request.Attributes);

                await _itemRepository.Insert(new Item()
                {
                    Description   = request.Description,
                    Name          = request.Name,
                    Price         = request.Price,
                    SKU           = request.SKU,
                    CategoryID    = request.CategoryID,
                    SubCategoryID = request.SubcategoryID,
                    Pictures      = pictureURLs.Select(x => new ItemPicture()
                    {
                        URL = x
                    }).ToList(),
                    Attributes = request.Attributes
                                 ?.Select(x => new AttributeValue()
                    {
                        AttributeID = x.AttributeID, Value = x.Value
                    })
                                 ?.ToList()
                });

                await _itemRepository.SaveChanges();

                transaction.Commit();
            }
            return(StatusCode((int)HttpStatusCode.NoContent));
        }
Esempio n. 2
0
        public async Task AddItem(ItemCreateRequest request, string gameCode)
        {
            int.TryParse(Context.Items[KeyConstants.GameCode] as string, out int gameId);
            await _itemService.Add(request, gameId);

            var items = await _itemService.GetItemsByGameId(gameId);

            await Clients.Group(gameCode).RefreshItemList(items);
        }
        public async Task Add(ItemCreateRequest request, int gameId)
        {
            var item = new Item
            {
                Name        = request.Name,
                Description = request.Description,
                ImageLink   = request.ImageLink,
                GameId      = gameId
            };

            await _itemRepository.AddAsync(item);
        }
Esempio n. 4
0
 public Task <int> Create(ItemCreateRequest request)
 {
     throw new NotImplementedException();
 }