Beispiel #1
0
        public async Task <(bool state, object response)> store(NewProductRequest request)
        {
            var category = await _context.Category.FindAsync(request.CategoryId);

            if (category == null)
            {
                return(false, new { message = "Selected Category does not exists" });
            }

            var product = new Product {
                Name        = request.Name,
                Description = request.Description,
                Price       = request.Price,
                CategoryId  = request.CategoryId,
                CreatedAt   = DateTimeOffset.Now
            };

            await _context.AddAsync(product);

            await _context.SaveChangesAsync();


            return(true, transform(product));
        }