// To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(SkinType).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SkinTypeExists(SkinType.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(string[] selectedSkinTypes)
        {
            var newProduct = new Product();

            if (selectedSkinTypes != null)
            {
                newProduct.ProductSkinTypes = new List <ProductSkinType>();
                foreach (var skin in selectedSkinTypes)
                {
                    var skinToAdd = new ProductSkinType
                    {
                        SkinTypeID = int.Parse(skin)
                    };
                    newProduct.ProductSkinTypes.Add(skinToAdd);
                }
            }
            if (await TryUpdateModelAsync <Product>(newProduct, "Product", i => i.ProductName, i => i.BrandName, i => i.Price, i => i.ManufactureDate, i => i.ExpirationDate, i => i.LotNo, i => i.CategoryID))
            {
                _context.Product.Add(newProduct);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedSkinTypeData(_context, newProduct);
            return(Page());
        }
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Category.Add(Category);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

            return(RedirectToPage("./Index"));
        }
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int?id, string[] selectedSkinTypes)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var productToUpdate = await _context.Product.Include(i => i.Category).Include(i => i.ProductSkinTypes).ThenInclude(i => i.SkinType).FirstOrDefaultAsync(s => s.ID == id);

            if (productToUpdate == null)
            {
                return(NotFound());
            }
            if (await TryUpdateModelAsync <Product>(productToUpdate, "Product", i => i.ProductName, i => i.BrandName, i => i.Price, i => i.ManufactureDate, i => i.ExpirationDate, i => i.LotNo, i => i.Category))
            {
                UpdateProductSkinTypes(_context, selectedSkinTypes, productToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            UpdateProductSkinTypes(_context, selectedSkinTypes, productToUpdate);
            PopulateAssignedSkinTypeData(_context, productToUpdate);
            return(Page());
        }