Exemple #1
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ProductProperty = await _context.ProductProperty.FirstOrDefaultAsync(m => m.ProductPropertyId == id);

            if (ProductProperty == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemple #2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ProductProperty = await _context.ProductProperty.FindAsync(id);

            if (ProductProperty != null)
            {
                _context.ProductProperty.Remove(ProductProperty);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemple #3
0
        public async Task <Guid> Add(AddProductViewModel model)
        {
            var product = new Models.Product()
            {
                Name        = model.Name,
                CreatedAt   = DateTime.Now,
                CategoryId  = model.CategoryId,
                Description = model.Description,
                Price       = model.Price
            };

            Context.Products.Add(product);
            await Context.SaveChangesAsync();

            if (model.Properties != null)
            {
                foreach (var propery in model.Properties)
                {
                    if (string.IsNullOrWhiteSpace(propery.Value))
                    {
                        continue;
                    }

                    var productProperty = new Models.ProductProperty()
                    {
                        ProductId          = product.Id,
                        CategoryPropertyId = propery.Key,
                        Value     = propery.Value,
                        CreatedAt = DateTime.Now
                    };
                    Context.ProductProperties.Add(productProperty);
                    await Context.SaveChangesAsync();
                }
            }

            return(product.Id);
        }